Created
December 1, 2020 13:35
-
-
Save heron2014/df45a50e846e630fd6da5386442aa59d to your computer and use it in GitHub Desktop.
useEffect componentDidUpdate
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
// Class | |
componentDidUpdate(prevProps, prevState) { | |
console.log('Prev state', prevState); // Before update | |
console.log('New state', this.state); // After update | |
} | |
// Hooks | |
useEffect(() => { | |
// The big difference here is that useEffect doesn't provide previous state/prop value. | |
// There are custom hooks to do that but useEffect doesn't do that out of the box. | |
console.log('Run this arrow function only when the component is first rendered/mounted and when the `value` changes'); | |
}, [value]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment