Created
July 12, 2023 12:10
-
-
Save Ricki-BumbleDev/f4a8544b3afa203554f911d587736f3b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { DependencyList, EffectCallback, useEffect, useRef } from 'react'; | |
const useDeepEffect = (effect: EffectCallback, deps?: DependencyList) => { | |
const prevDepsRef = useRef<DependencyList>(); | |
useEffect(() => { | |
if (JSON.stringify(deps) === JSON.stringify(prevDepsRef.current)) { | |
return; | |
} | |
prevDepsRef.current = deps; | |
return effect(); | |
}, deps); | |
}; | |
export default useDeepEffect; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment