UseTimeout
guarahooks/use-timeoutFreeHook
Executes a callback after a specified delay.
Live preview
live · rendered by the registry
Rendered by guarahooks on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://guarahooks.com/r/use-timeout.jsonSource
1'use client';23import { useEffect, useRef } from 'react';45export function useTimeout(callback: () => void, delay: number | null): void {6 const savedCallback = useRef(callback);78 // Remember the latest callback if it changes9 useEffect(() => {10 savedCallback.current = callback;11 }, [callback]);1213 // Set up the timeout14 useEffect(() => {15 if (delay === null) {16 return;17 }1819 const id = setTimeout(() => {20 savedCallback.current();21 }, delay);2223 return () => clearTimeout(id);24 }, [delay]);25}
Files it writes
More from guarahooks
All 100 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| UseAbortControlleruse-abort-controller | guarahooks | Hooks | Free | no deps | |
| UseArrayStateuse-array-state | guarahooks | Hooks | Free | no deps | |
| UseAxiosuse-axios | guarahooks | Hooks | Free | no deps | |
| UseBatteryStatususe-battery-status | guarahooks | Hooks | Free | no deps | |
| UseBetterAuthuse-better-auth | guarahooks | Hooks | Free | no deps | |
| UseClickOutsideuse-click-outside | guarahooks | Hooks | Free | no deps | |
| UseConfirmuse-confirm | guarahooks | Hooks | Free | no deps | |
| UseCookieuse-cookie | guarahooks | Hooks | Free | no deps |
