Last active
June 27, 2023 15:31
-
-
Save deviationist/1788444263d77159fba0e9415ef6aacc to your computer and use it in GitHub Desktop.
React's useEffect, but it does not run on initial render.
This file contains 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 React from 'react'; | |
export function useEffectNonInit(effect: Function, deps: React.DependencyList) { | |
const isInitial = React.useRef(true); | |
React.useEffect(() => { | |
if (isInitial.current) { | |
isInitial.current = false; | |
return; | |
} | |
effect(); | |
}, deps); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment