Skip to content

Instantly share code, notes, and snippets.

@dmorenogogoleva
Last active April 26, 2021 08:20
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 dmorenogogoleva/1f0be839d0bef748b54a25ce2323cb44 to your computer and use it in GitHub Desktop.
Save dmorenogogoleva/1f0be839d0bef748b54a25ce2323cb44 to your computer and use it in GitHub Desktop.
use-previous typescript hook
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