Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 975f52d

Browse files
committed
Use bind again because eventListener won’t be found
Check for (typeof document !== ‚undefined‘)
1 parent 97b027c commit 975f52d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/component/escapable.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ import { Component } from 'react';
22
import PropTypes from 'prop-types';
33

44
class Escapable extends Component {
5+
constructor(props) {
6+
super(props);
7+
this.handleKeyDown = this.handleKeyDown.bind(this);
8+
}
9+
510
componentDidMount() {
6-
if (document) {
7-
document.addEventListener('keydown', e => this.handleKeyDown(e));
11+
if (typeof document !== 'undefined') {
12+
document.addEventListener('keydown', this.handleKeyDown);
813
}
914
}
1015

1116
componentWillUnmount() {
12-
if (document) {
13-
document.removeEventListener('keydown', e => this.handleKeyDown(e));
17+
if (typeof document !== 'undefined') {
18+
document.removeEventListener('keydown', this.handleKeyDown);
1419
}
1520
}
1621

0 commit comments

Comments
 (0)