Open hello2jolee opened 3 years ago
useEffect(() => {
if (element.current) { // componentDidMount → add an effect
element.current.addEventListener("click", onClick);
}
return () => element.current.removeEventListener("click", onClick); // componentWillUnmount → remove an effect (clean up after myself)
});
useEffect
== componentWillUnmount, componentDidMount, componentWillUpdate