useLatest
FunctionuseLatest<T>(value: T): RefObject<T>A Hook that returns the latest value, effectively avoiding the closure problem.
Type Parameters
| Parameter | Type |
|---|---|
T |
Parameters
| Parameter | Type |
|---|---|
value | T |
Returns
RefObject<T>example:
const valueRef = useLatest(value)
React.useEffect(() => {
console.log(valueRef.current)
}, [valueRef])