Created
May 7, 2020 11:49
-
-
Save Mazuh/f31e1d3fd531ce946109d07e18ee2602 to your computer and use it in GitHub Desktop.
usePrevious hook for React to track data changes between renderings
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 React from 'react'; | |
export default function usePrevious(value) { | |
const ref = React.useRef(); | |
React.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