Answers for "click button binding after useeffect"

0

click button binding after useeffect

() => {
  useEffect(() => {
    const clicked = () => console.log('window clicked')
    window.addEventListener('click', clicked)

    // return a clean-up function
    return () => {
          window.addEventListener('click', function() {
            console.log('new');
          });
    }
  }, [])

  return <div>
    When you click the window you'll 
    find a message logged to the console
  </div>
}
Posted by: Guest on July-31-2021

Code answers related to "click button binding after useeffect"

Browse Popular Code Answers by Language