Created
December 3, 2018 13:09
-
-
Save danakt/75ac3fc09adb0a66e6962d31dcc846ac to your computer and use it in GitHub Desktop.
React hook to use previous data
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
/** | |
* React hook to use previous data | |
*/ | |
const usePrevious = function<T>(value: T): undefined | T { | |
const ref = React.useRef<T | undefined>(undefined); | |
React.useEffect(() => { | |
ref.current = value; | |
}); | |
return ref.current; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment