-
-
Save Eliav2/8a3aaac86d891afaacf6e84c9edaae5f to your computer and use it in GitHub Desktop.
This file contains 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
const useLog = (componentName = '', effect = useEffect) => { | |
// keep track of phase | |
const render = useRef(0); | |
const call = useRef(0); | |
// keep track of how much time from update call to end of effect | |
const startTime = performance.now(); | |
const callToEffectTime = useRef(0); | |
const consoleState = () => | |
`{call:${call.current},render:${render.current}}(${componentName}) ${callToEffectTime.current}ms`; | |
const log = (...args) => console.log(...args, consoleState()); | |
effect(() => { | |
render.current += 1; | |
callToEffectTime.current = Math.round((performance.now() - startTime) * 100) / 100; | |
}); | |
call.current += 1; | |
return log; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment