Created
October 15, 2022 03:28
-
-
Save liammclennan/2bc9856cd664bb5cd2078457099044bb to your computer and use it in GitHub Desktop.
React `useEffect`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function App() { | |
let divRef = useRef(null); | |
useEffect(() => { | |
var text = document.createTextNode(" Rendered "); | |
divRef.current.appendChild(text); | |
return () => { | |
var text = document.createTextNode(" Unrendered "); | |
divRef.current.appendChild(text); | |
}; | |
}); | |
useEffect(() => { | |
var text = document.createTextNode(" Mounted "); | |
divRef.current.appendChild(text); | |
return () => { | |
var text = document.createTextNode(" Unmounted "); | |
divRef.current.appendChild(text); | |
}; | |
}, []); | |
return ( | |
<div className="App" ref={divRef}> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment