Spaces:
Running
Running
File size: 372 Bytes
c2b7eb3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | import { useEffect, useRef } from './reactImports'
import { shallowEqual } from './reactReduxImports'
export function useShallowStableValue<T>(value: T) {
const cache = useRef(value)
useEffect(() => {
if (!shallowEqual(cache.current, value)) {
cache.current = value
}
}, [value])
return shallowEqual(cache.current, value) ? cache.current : value
}
|