Skip to Content
⭐️ Leave a star →
HooksuseTimeout

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

ParamTypeDescription
callback() => voidFires when the timer elapses.
delaynumberMilliseconds before callback runs.
options{ autoStart?: boolean }Start the timer on mount. Defaults to false.

Returns

KeyTypeDescription
isPendingbooleantrue while the timer is queued.
start() => voidBegin the timer. Replaces any in-flight timer.
stop() => voidCancel the timer.
reset() => voidCancel and restart with the current delay.
Last updated on

MIT License © 2026 wire-ui

useTimeout – Wire UI