https://github.com/tj/react-click-outside
или
handleClick() {
if (!this.state.active) {
// attach/remove event handler
document.addEventListener('click', this.handleOutsideClick, false);
} else {
document.removeEventListener('click', this.handleOutsideClick, false);
}
this.setState(prevState => ({
active: !prevState.active,
}));
}
handleOutsideClick(e) {
// ignore clicks on the component itself
console.log('EVENT handleOutsideClick ', e)
if (this.node.contains(e.target)) {
return;
}
this.handleClick();
}
на элемент за пределами которого кликают добавить ref
ref={node => { this.node = node; }}
<li className='notif_container' ref={node => { this.node = node; }}>
{this.button()}
</li>