shadcn-ahooks

useTimeout

A hook that handles the setTimeout timer function.

Overview

A hook that handles the setTimeout timer function.

Documentation and Examples

Installation

Open in
pnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTimeout.json
npx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTimeout.json
yarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTimeout.json
bun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTimeout.json

A hook that handles the setTimeout timer function.

Examples

Default usage

  • Modify the delay to realize the timer timeout change and pause.

API

useTimeout(
  fn: () => void,
  delay?: number | undefined
): fn: () => void;

Params

PropertyDescriptionType
fnThe function to be executed after delay milliseconds.() => void
delayThe number of milliseconds to wait before executing the function. The timer will be cancelled if delay is undefined.number | undefined

Result

PropertyDescriptionType
clearTimeoutclear timeout() => void

On this page