File size: 297 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import { useState } from 'react';
import { dequal } from '../lib/dequal';
export function useStableValue<TValue>(value: TValue) {
const [stableValue, setStableValue] = useState<TValue>(() => value);
if (!dequal(stableValue, value)) {
setStableValue(value);
}
return stableValue;
}
|