Skip to content

Instantly share code, notes, and snippets.

@erictherobot
Created April 30, 2021 14:26
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 erictherobot/328c9381f7c789bef2c76b55776f4da8 to your computer and use it in GitHub Desktop.
Save erictherobot/328c9381f7c789bef2c76b55776f4da8 to your computer and use it in GitHub Desktop.
Get Previous Hook
import { useRef, useEffect } from 'react';
export function usePrevious(value: any) {
const ref = useRef();
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