Created
January 25, 2020 19:47
-
-
Save khusamov/a2abf34530177eeb717c4f7335a71155 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
import {useEffect, useRef} from "react"; | |
/** | |
* Хук возвращающий предыдущее состояние | |
* @param value | |
*/ | |
export const usePrevious = (value: any) => { | |
const ref = useRef(null); | |
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