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