Created
December 16, 2019 20:59
-
-
Save stephenway/b89b66cddf554648d4cf114f6e19bad2 to your computer and use it in GitHub Desktop.
React Hook to Expose previous props for use in useEffect 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 } from 'react' | |
const usePrevious = value => { | |
const ref = useRef() | |
useEffect(() => { | |
ref.current = 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