useLatencyBoundValue()
ts
function useLatencyBoundValue<T>(value, latency): T;Defined in: latency.ts:86
React hook for replaying state updated with a specified latency.
Type Parameters
| Type Parameter | Description |
|---|---|
T | Type of the initial value |
Parameters
| Parameter | Type | Description |
|---|---|---|
value | T | Initial state value |
latency | number | Latency in milliseconds to delay state updates |
Returns
T
Value T with latency
Example
tsx
function MyComponent () {
const [value, setValue] = useState("initial");
const latencyValue = useLatencyBoundValue(value, 1000);
useEffect(() => {
setValue("updated");
}, [])
return (
<>
<!-- The value will update with a delay of 1 second after calling setValue -->
<p>{latencyValue}</p>
</>
)
}Since
1.0.0
Author
Simon Kovtyk