Created
December 18, 2021 08:49
-
-
Save 0xLDev/2936420b6380e6ad94460be95c96294b to your computer and use it in GitHub Desktop.
This file contains hidden or 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'; | |
export const useMountedRef = () => { | |
const isMountedRef = useRef(true); | |
useEffect(() => { | |
const beforeUnmount = () => { | |
isMountedRef.current = false; | |
}; | |
return beforeUnmount; | |
}, []); | |
return isMountedRef; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment