Files
yaak/src-web/hooks/useDebouncedState.ts
Gregory Schier 5919fae739 Run oxfmt across repo, add format script and ignore config
Format all non-generated files with oxfmt via `vp fmt`. Add
.oxfmtignore to skip bindings/ and wasm-pack output. Add npm
format script and update DEVELOPMENT.md docs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 09:52:11 -07:00

13 lines
471 B
TypeScript

import { debounce } from "@yaakapp-internal/lib";
import type { Dispatch, SetStateAction } from "react";
import { useMemo, useState } from "react";
export function useDebouncedState<T>(
defaultValue: T,
delay = 500,
): [T, Dispatch<SetStateAction<T>>, Dispatch<SetStateAction<T>>] {
const [state, setState] = useState<T>(defaultValue);
const debouncedSetState = useMemo(() => debounce(setState, delay), [delay]);
return [state, debouncedSetState, setState];
}