Created
December 3, 2019 01:20
-
-
Save compulim/5ed44024ba5ef830be957f16944879ec to your computer and use it in GitHub Desktop.
Detect deps change in React
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
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