Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. const EffectCleanup = () => {
  2. useEffect(() => {
  3. const clicked = () => console.log('window clicked')
  4. window.addEventListener('click', clicked)
  5.  
  6. // return a clean-up function
  7. return () => {
  8. window.removeEventListener('click', clicked)
  9. }
  10. }, [])
  11.  
  12. return <div>
  13. When you click the window you'll
  14. find a message logged to the console
  15. </div>
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement