12 lines
No EOL
254 B
TypeScript
12 lines
No EOL
254 B
TypeScript
import { useRef } from 'react'
|
|
import { useIsoMorphicEffect } from './useIsoMorphicEffect'
|
|
|
|
export function useLatestValue<T>(value: T) {
|
|
let cache = useRef(value)
|
|
|
|
useIsoMorphicEffect(() => {
|
|
cache.current = value
|
|
}, [value])
|
|
|
|
return cache
|
|
} |