Skip to content

Instantly share code, notes, and snippets.

@simbathesailor
Last active November 17, 2019 04:21
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 simbathesailor/6defb45314a6015bc1c74a7fb738ba12 to your computer and use it in GitHub Desktop.
Save simbathesailor/6defb45314a6015bc1c74a7fb738ba12 to your computer and use it in GitHub Desktop.
consumeuseprevious.jsx
const previousA = usePrevious(a);
const previousB = usePrevious(b);
const previousC = usePrevious(c);
useEffect(() => {
if (previousA !== a) {
console.log(`a has changed from ${previousA} to ${a}`);
}
if (previousB !== b) {
console.log(`a has changed from ${previousB} to ${b}`);
}
if (previousC !== c) {
console.log(`a has changed from ${previousC} to ${c}`);
}
}, [a, b, c]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment