Skip to content

Instantly share code, notes, and snippets.

@Ricki-BumbleDev
Created July 12, 2023 12:10
Show Gist options
  • Save Ricki-BumbleDev/f4a8544b3afa203554f911d587736f3b to your computer and use it in GitHub Desktop.
Save Ricki-BumbleDev/f4a8544b3afa203554f911d587736f3b to your computer and use it in GitHub Desktop.
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