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>
}