Last active
April 26, 2021 08:20
-
-
Save dmorenogogoleva/1f0be839d0bef748b54a25ce2323cb44 to your computer and use it in GitHub Desktop.
use-previous typescript 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
export function usePrevious<T> (value: T): T | undefined { | |
const ref = useRef<T>() | |
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