Skip to content

Instantly share code, notes, and snippets.

@donaldpipowitch
Created June 14, 2019 12:04
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 donaldpipowitch/460ecacee2de48a7a965b4c08eb358d7 to your computer and use it in GitHub Desktop.
Save donaldpipowitch/460ecacee2de48a7a965b4c08eb358d7 to your computer and use it in GitHub Desktop.
React Hook to use previous value
import { useEffect, useRef } from 'react';
function usePrevious<T>(value: T) {
const ref = useRef<T>();
useEffect(() => {
ref.current = value;
});
return ref.current;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment