hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import { 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 | */ |
| 7 | export 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 | } |