I\'m looking for a way to detect if a click event happened outside of a component, as described in this article. jQuery closest() is used to see if the target from a click e
componentWillMount(){ document.addEventListener('mousedown', this.handleClickOutside) } handleClickOutside(event) { if(event.path[0].id !== 'your-button'){ this.setState({showWhatever: false}) } }
Event path[0] is the last item clicked
path[0]