Skip to content

Instantly share code, notes, and snippets.

@ivillamil
Created September 20, 2021 13:44
Show Gist options
  • Save ivillamil/eca7a62f2f208964345e46cd3a6b562a to your computer and use it in GitHub Desktop.
Save ivillamil/eca7a62f2f208964345e46cd3a6b562a to your computer and use it in GitHub Desktop.
Effect hook that executes only after all components have been rendered
import {useEffect, useRef} from 'react'
const useEffectAfterMount = ( effect, deps ) => {
const isMounted = useRef(false)
useEffect(() => {
if (isMounted.current) {
return effect()
} else {
isMounted.current = true
}
}, [deps])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment