Created
May 25, 2022 10:23
-
-
Save hawx1993/9e8ff6041c4d88337b03fa5e47a3001f 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 { useCallback, useEffect, useRef } from 'react' | |
| function useIsMounted() { | |
| const isMounted = useRef(false) | |
| useEffect(() => { | |
| isMounted.current = true | |
| return () => { | |
| isMounted.current = false | |
| } | |
| }, []) | |
| return useCallback(() => isMounted.current, []) | |
| } | |
| export default useIsMounted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment