I'm a little confused what is the difference between this sintax:
constructor(props) { super(props); this.state = { openPane: false } this.togglePaneHelper = this.togglePaneHelper.bind(this); } componentDidMount() { document.body.addEventListener('click', this.togglePaneHelper); } componentWillUnmount() { document.body.removeEventListener('click', this.togglePaneHelper); }
and this one:
constructor(props) { super(props); this.state = { openPane: false } } componentDidMount() { document.body.addEventListener('click', this.togglePaneHelper.bind(this)); } componentWillUnmount() { document.body.removeEventListener('click', this.togglePaneHelper); }
My concern is that the second syntax does not correctly remove the listner and raise this warning:
Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the undefined component.
source share