Skip to content

Instantly share code, notes, and snippets.

@Mazuh
Created May 7, 2020 11:49
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 Mazuh/f31e1d3fd531ce946109d07e18ee2602 to your computer and use it in GitHub Desktop.
Save Mazuh/f31e1d3fd531ce946109d07e18ee2602 to your computer and use it in GitHub Desktop.
usePrevious hook for React to track data changes between renderings
import React from 'react';
export default function usePrevious(value) {
const ref = React.useRef();
React.useEffect(() => {
ref.current = value;
}, [value]);
return ref.current;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment