Skip to content

Instantly share code, notes, and snippets.

@SebastianHGonzalez
Created December 2, 2019 18:08
Show Gist options
  • Save SebastianHGonzalez/26e982f7b3852ea01fc41b525f70a5d9 to your computer and use it in GitHub Desktop.
Save SebastianHGonzalez/26e982f7b3852ea01fc41b525f70a5d9 to your computer and use it in GitHub Desktop.
import { useRef, useEffect } from 'react';
export default function usePrevious(value) {
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