Created
November 7, 2022 10:30
-
-
Save hawx1993/c063351032fbe77371b8f7f049a2f2d4 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
| function usePrevious(value) { | |
| const ref = useRef(); | |
| useEffect(() => { | |
| ref.current = value; //assign the value of ref to the argument | |
| }, [value]); //this code will run when the value of 'value' changes | |
| return ref.current || {}; //in the end, return the current ref value. | |
| } | |
| export { usePrevious }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment