Skip to content

Instantly share code, notes, and snippets.

@liammclennan
Created October 15, 2022 03:28
Show Gist options
  • Save liammclennan/2bc9856cd664bb5cd2078457099044bb to your computer and use it in GitHub Desktop.
Save liammclennan/2bc9856cd664bb5cd2078457099044bb to your computer and use it in GitHub Desktop.
React `useEffect`
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