mirror of
https://github.com/danog/react-datalist-input.git
synced 2025-01-22 13:52:41 +01:00
trying to make it ssr compatible
This commit is contained in:
parent
2e891f3e77
commit
7329e8818d
@ -3,6 +3,8 @@ import PropTypes from 'prop-types';
|
||||
|
||||
import './DataListInput.css';
|
||||
|
||||
const windowExists = () => typeof window !== 'undefined';
|
||||
|
||||
class DataListInput extends React.Component {
|
||||
constructor( props ) {
|
||||
super( props );
|
||||
@ -31,7 +33,9 @@ class DataListInput extends React.Component {
|
||||
}
|
||||
|
||||
componentDidMount = () => {
|
||||
window.addEventListener( 'click', this.onClickCloseMenu, false );
|
||||
if ( windowExists() ) {
|
||||
window.addEventListener( 'click', this.onClickCloseMenu, false );
|
||||
}
|
||||
}
|
||||
|
||||
componentDidUpdate = () => {
|
||||
@ -46,7 +50,9 @@ class DataListInput extends React.Component {
|
||||
}
|
||||
|
||||
componentWillUnmount = () => {
|
||||
window.removeEventListener( 'click', this.onClickCloseMenu );
|
||||
if ( windowExists() ) {
|
||||
window.removeEventListener( 'click', this.onClickCloseMenu );
|
||||
}
|
||||
}
|
||||
|
||||
onClickCloseMenu = ( event ) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user