useTimeout
A managed setTimeout. The handler is always the latest reference, so closure-captured values stay fresh even if you don’t reset. The timer is cleared automatically when the consumer unmounts.
Used internally by Alert, Avatar, Toast, and Tooltip for their delay/auto-dismiss timers.
import { useTimeout } from '@wire-ui/react'
function AutoDismiss({ onDismiss }: { onDismiss: () => void }) {
const { isPending, start, stop, reset } = useTimeout(onDismiss, 3000, { autoStart: true })
return (
<div onMouseEnter={stop} onMouseLeave={reset}>
{isPending ? 'closing soon…' : 'hovering'}
</div>
)
}Parameters
| Param | Type | Description |
|---|---|---|
callback | () => void | Fires when the timer elapses. |
delay | number | Milliseconds before callback runs. |
options | { autoStart?: boolean } | Start the timer on mount. Defaults to false. |
Returns
| Key | Type | Description |
|---|---|---|
isPending | boolean | true while the timer is queued. |
start | () => void | Begin the timer. Replaces any in-flight timer. |
stop | () => void | Cancel the timer. |
reset | () => void | Cancel and restart with the current delay. |
Last updated on