Skip to content

Instantly share code, notes, and snippets.

@simbathesailor
Created February 2, 2020 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simbathesailor/5f358866dba926d5cc504e9a601e7393 to your computer and use it in GitHub Desktop.
Save simbathesailor/5f358866dba926d5cc504e9a601e7393 to your computer and use it in GitHub Desktop.
useisMountedRefUsage.jsx
function App() {
const isMountedRefApproach = useIsMountedRef();
React.useEffect(() => {
if (isMountedRefApproach.current) {
console.log("I am mounted");
}
}, [isMountedRefApproach.current]);
React.useEffect(() => {
console.log("parent");
}, []);
console.log("isMountedRefApproach.current", isMountedRefApproach.current);
return (
<div>
<Child />
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment