Created
September 3, 2022 14:47
-
-
Save ZacharyL2/13030ceac10e70ff5c489ffd3ab2e9fb to your computer and use it in GitHub Desktop.
This file contains 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'; | |
const usePrevious = (value) => { | |
const ref = useRef(); | |
useEffect(() => { | |
ref.current = value; | |
}, [value]); | |
return ref.current; | |
}; | |
export default usePrevious; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment