Skip to content

Instantly share code, notes, and snippets.

@ohansemmanuel
Created April 13, 2019 08:14
Show Gist options
  • Select an option

  • Save ohansemmanuel/b0c213dd4e9a9ff417a68af86480cf80 to your computer and use it in GitHub Desktop.

Select an option

Save ohansemmanuel/b0c213dd4e9a9ff417a68af86480cf80 to your computer and use it in GitHub Desktop.
const EffectCleanup = () => {
useEffect(() => {
const clicked = () => console.log('window clicked')
window.addEventListener('click', clicked)
// return a clean-up function
return () => {
window.removeEventListener('click', clicked)
}
}, [])
return <div>
When you click the window you'll
find a message logged to the console
</div>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment