forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

create-debounced-signal.ts18 lines, 676 bytesHistoryRawDownload
1import { createSignal, onCleanup } from "solid-js";
2
3/**
4 * Text input signal plus a copy that only catches up `delay` ms after typing
5 * stops — bind the raw one to the input, the debounced one to the query params.
6 */
7export function createDebouncedSignal(initial = "", delay = 300) {
8 const [raw, setRaw] = createSignal(initial);
9 const [debounced, setDebounced] = createSignal(initial);
10 let timer: ReturnType<typeof setTimeout> | undefined;
11 const set = (value: string) => {
12 setRaw(value);
13 clearTimeout(timer);
14 timer = setTimeout(() => setDebounced(value), delay);
15 };
16 onCleanup(() => clearTimeout(timer));
17 return [raw, set, debounced] as const;
18}