Skip to Content
HooksuseTimeout

useTimeout

useTimeout schedules a callback and gives you small controls to clear or restart that timer.

Live Example

Auto-dismiss timer

This demo shows a timer-driven banner flow with start, reset, clear, and pending state.

Auto-dismiss message

Banner cycle 1

Idle
Workspace synced successfully.

This banner dismisses after 4 seconds when the timer is armed.

Import

import { useTimeout } from "react-rsc-kit/client";

Signature

const { start, reset, clear, isPending } = useTimeout(callback, delay, options?);

Parameters

NameTypeDefaultDescription
callback() => voidrequiredFunction that runs when the timeout completes.
delaynumber | null | undefinedrequiredDelay in milliseconds. Use null or undefined to disable scheduling.
options.autoStartbooleantrueStarts the timeout automatically when enabled.

Returns

KeyDescription
startStarts the timeout manually.
resetClears and starts the timeout again.
clearClears the current timeout.
isPendingWhether a timeout is currently active.

Usage

"use client"; import { useState } from "react"; import { useTimeout } from "react-rsc-kit/client"; export function TimeoutBanner() { const [visible, setVisible] = useState(true); const { start, clear, reset, isPending } = useTimeout(() => setVisible(false), 5000, { autoStart: false, }); return ( <div> <p>{visible ? "Banner visible" : "Banner hidden"}</p> <p>Pending: {String(isPending)}</p> <button type="button" onClick={() => { setVisible(true); start(); }} > Start Timeout </button> <button type="button" onClick={clear}> Clear Timeout </button> <button type="button" onClick={() => { setVisible(true); reset(); }} > Reset Timeout </button> </div> ); }

Notes

  • autoStart defaults to true.
  • delay can be null to disable scheduling.
  • start, clear, and reset are designed for small UI timer flows.
  • Use this for dismissible UI or simple delayed effects.
Last updated on