Skip to content

Instantly share code, notes, and snippets.

@jsun969
Created November 2, 2023 20:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsun969/102413cdf730a0942483f5fa2fe80167 to your computer and use it in GitHub Desktop.
Save jsun969/102413cdf730a0942483f5fa2fe80167 to your computer and use it in GitHub Desktop.
use f**king mount
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