Hooks
useDebouncedValue
A hook that debounces a value.
npx shadcn@latest add https://hookagain.vercel.app/r/use-debounced-value.json
import { useDebouncedValue } from "@/hooks/use-debounced-value"
function Example() {
const [value, setValue] = React.useState("")
const debouncedValue = useDebouncedValue(value, 500) // 500ms delay
return (
<div className="flex flex-col gap-4">
<input
type="text"
value={value}
onChange={(e) => setValue(e.target.value)}
placeholder="Type something..."
className="border p-2 rounded"
/>
<p>Actual value: {value}</p>
<p>Debounced value: {debouncedValue}</p>
</div>
)
}