Created
November 2, 2023 20:26
-
-
Save jsun969/102413cdf730a0942483f5fa2fe80167 to your computer and use it in GitHub Desktop.
use f**king mount
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 useMount = (fn: React.EffectCallback) => { | |
const isMounted = useRef(false) | |
useEffect(() => { | |
if (!isMounted.current) { | |
fn() | |
isMounted.current = true | |
} | |
}, []) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment