useDebounce
Delay a value with useDebounce until it stops changing, for example before the value feeds a request.
Typing fires a change on every key. useDebounce returns a copy of a value that follows the value only after the value stays the same for a wait. The hook does not depend on the grid.
pnpm dlx shadcn@latest add @gridcn/use-debounce
The item installs to components/gridcn/use-debounce.ts. The same file holds useDebouncedInput.
useDebounce
function useDebounce<T>(value: T, delay?: number | { delayMs?: number }): T;Debounce a state value before it feeds a request:
import { useState } from "react";
import { useDebounce } from "@/components/gridcn/use-debounce";
export function SearchBox() {
const [query, setQuery] = useState("");
const debouncedQuery = useDebounce(query, 300);
return (
<>
<input value={query} onChange={(e) => setQuery(e.target.value)} />
<p>Searching for {debouncedQuery}</p>
</>
);
}The input shows each keystroke at once. The line below it changes 300 ms after the last keystroke.
Arguments
| Argument | Type | Default |
|---|---|---|
value | T | Required |
delay | number | { delayMs?: number } | 300 |
Behavior
- The first render returns
value. - Each change of
valueordelayMsrestarts the wait. - An unmount cancels a pending update.
- With a delay of
0or less, the hook returnsvalueitself and sets no timer.
inputDebounceMs
The grid waits for typing in its own text inputs through useDebouncedInput. Quick search describes the inputDebounceMs prop.
Related
- useDebouncedInput: commit the text of an input after the typing pauses.
- Server rows example: wait for typing to pause: a wait inside
fetchRows. - Quick search: the toolbar search that waits for typing to pause.
Store hooks
Look up each hook that reads grid state or reaches the grid from code, with its return value and the page that uses it.
useDebouncedInput
Drive a text input that shows each keystroke at once, calls `onCommit` when the typing pauses, and keeps the last keystrokes on blur, Enter, and unmount.