Created
November 2, 2019 20:14
-
-
Save compulim/6bae0b322cc829dc11f02c03af9562a2 to your computer and use it in GitHub Desktop.
Debug which props changed for React Hooks
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
function useLayoutEffectDebug(fn, deps) { | |
const [lastDeps, setLastDeps] = useState([]); | |
useLayoutEffect(() => { | |
console.log({ lastDeps, deps }); | |
lastDeps && console.log(deps.findIndex((value, index) => value !== lastDeps[index])); | |
setLastDeps(deps); | |
return fn(); | |
}, deps); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment