Skip to content

Instantly share code, notes, and snippets.

@heron2014
Created December 1, 2020 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heron2014/df45a50e846e630fd6da5386442aa59d to your computer and use it in GitHub Desktop.
Save heron2014/df45a50e846e630fd6da5386442aa59d to your computer and use it in GitHub Desktop.
useEffect componentDidUpdate
// 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