Created
March 8, 2024 23:43
-
-
Save cheskoxd/f60cf707d03a916646a9ed5ca8700309 to your computer and use it in GitHub Desktop.
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 { useEffect, useRef } from "react"; | |
export const usePrevious = <T>(value: T) => { | |
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