trying to make it ssr compatible

This commit is contained in:
andrelandgraf 2020-04-28 06:23:38 +02:00
parent 2e891f3e77
commit 7329e8818d

View File

@ -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 ) => {