Skip to content

Instantly share code, notes, and snippets.

@hawx1993
Created May 25, 2022 10:23
Show Gist options
  • Select an option

  • Save hawx1993/9e8ff6041c4d88337b03fa5e47a3001f to your computer and use it in GitHub Desktop.

Select an option

Save hawx1993/9e8ff6041c4d88337b03fa5e47a3001f to your computer and use it in GitHub Desktop.
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