Skip to content

Instantly share code, notes, and snippets.

@InfiniteXyy
Last active February 5, 2021 07:24
Show Gist options
  • Save InfiniteXyy/bafa9574dca0f2097e21251204685257 to your computer and use it in GitHub Desktop.
Save InfiniteXyy/bafa9574dca0f2097e21251204685257 to your computer and use it in GitHub Desktop.
const whyChangeRef = React.useRef({})
React.useEffect(() => {
console.log('why am i rendered?')
Object.keys(props).forEach((key) => {
const before = whyChangeRef.current[key]
const current = props[key]
if (before !== current) {
console.log(key + ' changed', [before, current])
}
})
whyChangeRef.current = props
}, Object.values(props))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment