Skip to content

Instantly share code, notes, and snippets.

@vladanyes
Created September 19, 2018 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladanyes/e6085b12789bd44fbcd219a52102c0d8 to your computer and use it in GitHub Desktop.
Save vladanyes/e6085b12789bd44fbcd219a52102c0d8 to your computer and use it in GitHub Desktop.
React click outside element.(no ref)
iconClick = () => {
if (this.state.showMenu === 'none') {
this.showMenu();
document.addEventListener('click', this.iconClickOutside);
} else if (this.state.showMenu === 'flex') {
this.hideMenu();
document.removeEventListener('click', this.iconClickOutside);
}
}
iconClickOutside = (e) => {
if(e.target.id !== 'swe-settings-item') {
this.hideMenu();
return
}
this.iconClick()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment