Shadcn Hooks

useInterval

A hook that creates an interval.

Loading...

Installation

npx shadcn@latest add @shadcnhooks/use-interval

API

/**
 * A hook that creates an interval.
 * @param fn - The function to execute repeatedly
 * @param delay - The delay in milliseconds between each execution. Set to null to pause the interval
 * @param options - The options for the interval
 * @param options.immediate - Whether to execute the function immediately
 * @default { immediate: false } if not provided
 * @returns A function to clear the interval
 */
export function useInterval(
  fn: () => void,
  delay: number | null = null,
  options?: { immediate?: boolean },
): () => void

Credits

Last updated on

On this page