useResettableTimeout
Restartable timeout controls with explicit start and clear methods.
Use useResettableTimeout to schedule a single timeout that resets on repeated starts.
Usage
import { useResettableTimeout } from "@tilt-legal/cubitt-components/utilities/hooks";
const { start, clear } = useResettableTimeout(() => {
setOpen(false);
}, 300);
start(); // schedules callback in 300ms
start(500); // resets and schedules for 500ms
clear(); // cancels pending callbackAPI
Parameters
| Option | Type | Description | Default |
|---|---|---|---|
callback | () => void | Function called when the timeout fires | - |
delay | number | Timeout duration in milliseconds | - |
Return Value
| Value | Type | Description |
|---|---|---|
start | (delayOverride?: number) => void | Starts the timeout and resets any active timer |
clear | () => void | Cancels the currently scheduled timeout |
Behavior
startalways clears any pending timer before creating a new one.- The latest callback reference is used when the timeout fires.
- Pending timers are cleaned up on unmount.
useInterval
Custom hook that creates an interval that invokes a callback function at a specified delay using the [`setInterval API`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval).
useTimeout
Custom hook that handles timeouts in React components using the [`setTimeout API`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout).