Skip to content

Instantly share code, notes, and snippets.

@compulim
Created December 3, 2019 01:20
Show Gist options
  • Save compulim/5ed44024ba5ef830be957f16944879ec to your computer and use it in GitHub Desktop.
Save compulim/5ed44024ba5ef830be957f16944879ec to your computer and use it in GitHub Desktop.
Detect deps change in React
export default function useDetectDepsChange(deps) {
const prevDeps = useRef([]);
deps.forEach((value, index) => {
if (prevDeps.current[index] !== value) {
console.log('Dep changed', { index, dep, prevDep: prevDeps.current[index] });
}
});
prevDeps.current = [...deps];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment