use-throttle
shadcn-hooks/use-throttleFreeHook
A hook to throttle a value
Install it
npx shadcn@latest add https://shadcn-hooks.com/r/use-throttle.jsonSource
1import { useEffect, useState } from 'react'2import { useThrottleFn } from '@/registry/hooks/use-throttle-fn'3import type { ThrottleOptions } from '@/registry/hooks/use-throttle-fn'45export function useThrottle<T>(6 value: T,7 throttleMs?: number,8 options?: ThrottleOptions,9) {10 const [throttledValue, setThrottledValue] = useState<T>(value)1112 const { run } = useThrottleFn(13 () => {14 setThrottledValue(value)15 },16 throttleMs,17 options,18 )1920 useEffect(() => {21 run()22 }, [value, run])2324 return throttledValue25}
What it pulls in
Other registry items
Files it writes
More from shadcn-hooks
All 58 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| use-active-elementuse-active-element | shadcn-hooks | Hooks | Free | no deps | |
| use-batteryuse-battery | shadcn-hooks | Hooks | Free | no deps | |
| use-booleanuse-boolean | shadcn-hooks | Hooks | Free | no deps | |
| use-click-any-whereuse-click-any-where | shadcn-hooks | Hooks | Free | no deps | |
| use-click-awayuse-click-away | shadcn-hooks | Hooks | Free | no deps | |
| use-clipboarduse-clipboard | shadcn-hooks | Hooks | Free | no deps | |
| use-controllable-valueuse-controllable-value | shadcn-hooks | Hooks | Free | 1 dep | |
| use-counteruse-counter | shadcn-hooks | Hooks | Free | no deps |
