Created
November 7, 2021 14:14
-
-
Save enqtran/4cefb87b2560ca6d467b0e6c837ba959 to your computer and use it in GitHub Desktop.
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
import { useEffect, useRef } from "react" | |
/* | |
isMounted = useIsMounted() | |
useEffect(() => { | |
if (isMounted.current) { | |
// code... | |
} | |
}, [isMounted]) | |
*/ | |
const useIsMounted = () => { | |
const isMounted = useRef(null) | |
useEffect(() => { | |
isMounted.current = true | |
return () => { | |
isMounted.current = false | |
} | |
}) | |
return isMounted | |
} | |
export default useIsMounted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment