Last active
March 11, 2024 15:45
-
-
Save deviationist/b1005c39c8fd270606648053d48a55fe to your computer and use it in GitHub Desktop.
React's useEffect, but it does not run on initial render. Now with TypeScript-support.
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
/* eslint-disable react-hooks/exhaustive-deps */ | |
import { useEffect, useRef, DependencyList } from 'react'; | |
export const useEffectNonInit = (effect: Function, deps: DependencyList = []) => { | |
const isInitial = useRef<boolean>(true); | |
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