Docs
useTimeout

Run a callback function after a specified delay with useTimeout.

You have 1s to defuse (click) the bomb or it will explode

Installation

pnpm dlx shadcn@latest add https://hookcn.ouassim.tech/r/use-timeout

Usage

"use client"
 
import * as React from "react"
 
import { useTimeout } from "@/hooks/use-timeout"
 
export function Component() {
  const [hasTimeElapsed, setHasTimeElapsed] = React.useState(false)
 
  useTimeout(() => {
    setHasTimeElapsed(true)
  }, 5000)
 
  return (
    <p>{hasTimeElapsed ? "5 seconds has passed!" : "The timer is running…"}</p>
  )
}

API Reference

Parameters

NameTypeDescription
callback() => voidThe function to be executed when the timeout elapses.
delaynull | numberThe duration (in milliseconds) for the timeout. Set to null to clear the timeout.