Created
April 30, 2021 14:26
-
-
Save erictherobot/328c9381f7c789bef2c76b55776f4da8 to your computer and use it in GitHub Desktop.
Get Previous Hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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