Skip to content

Instantly share code, notes, and snippets.

@huykon
Last active April 6, 2021 01:56
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 huykon/ccd861548fd412b73869eac37bbadf43 to your computer and use it in GitHub Desktop.
Save huykon/ccd861548fd412b73869eac37bbadf43 to your computer and use it in GitHub Desktop.
Custom hook store previous state
import { useEffect, useRef } from 'react';
export function usePrevious(value) {
const ref = useRef();
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