shadcn-ahooks

useInterval

A hook that handles the setInterval timer function.

Overview

A hook that handles the setInterval timer function.

Documentation and Examples

Installation

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

A hook that handles the setInterval timer function.

Examples

Default usage

Advanced usage

API

useInterval(
  fn: () => void,
  delay?: number | undefined,
  options?: Options
): fn: () => void;

Params

| Property | Description | Type | | -- | - | | | - | | immediate | Whether the function should be executed immediately on first execution | boolean | false |

Result

| Property | Description | Type | | - | -- | | | clearInterval | clear interval | () => void |

On this page