Skip to content

Commit 3947c24

Browse files
committed
frontend: remove unsafe componnetwillmount fix esc in webdev
When Strict Mode is on, React will also run one extra setup+cleanup cycle in development. This helps reveal subtle bugs that are hard to catch manually. This also makes the deprecated UNSAFE componentWillMount only run first time. Send view used UNSAFE_componentWillMount to listen to keydown events that handles ESC button. In webdev pressing ESC button did therefore not go back to the account overview. Changed to register events on componentDidMount. Also changed deprecated KeyBoardEvent.keyCode to KeyBoardEvent.key. See: - https://react.dev/reference/react/StrictMode - https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
1 parent ba9a721 commit 3947c24

File tree

1 file changed

+3
-10
lines changed
  • frontends/web/src/routes/account/send

1 file changed

+3
-10
lines changed

frontends/web/src/routes/account/send/send.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ class Send extends Component<Props, State> {
166166
}
167167
}),
168168
];
169-
}
170169

171-
public UNSAFE_componentWillMount() {
172170
this.registerEvents();
173171
}
174172

@@ -177,16 +175,11 @@ class Send extends Component<Props, State> {
177175
unsubscribe(this.unsubscribeList);
178176
}
179177

180-
private registerEvents = () => {
181-
document.addEventListener('keydown', this.handleKeyDown);
182-
};
183-
184-
private unregisterEvents = () => {
185-
document.removeEventListener('keydown', this.handleKeyDown);
186-
};
178+
private registerEvents = () => document.addEventListener('keydown', this.handleKeyDown);
179+
private unregisterEvents = () => document.removeEventListener('keydown', this.handleKeyDown);
187180

188181
private handleKeyDown = (e: KeyboardEvent) => {
189-
if (e.keyCode === 27 && !this.state.activeCoinControl && !this.state.activeScanQR) {
182+
if (e.key === 'Escape' && !this.state.activeCoinControl && !this.state.activeScanQR) {
190183
route(`/account/${this.props.code}`);
191184
}
192185
};

0 commit comments

Comments
 (0)