Created
April 4, 2020 14:41
-
-
Save pavermakov/c278273cbf1151518d3e7cbb01ca418d 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 { useCallback, useEffect, useRef } from 'react'; | |
export function useMounted() { | |
const refMounted = useRef(false); | |
useEffect(() => { | |
refMounted.current = true; | |
return () => { | |
refMounted.current = false; | |
}; | |
}); | |
const isMounted = useCallback(() => { | |
return refMounted.current; | |
}, []); | |
return isMounted; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment