Refactor debounce and tauri event listeners

This commit is contained in:
Gregory Schier
2023-04-01 21:39:46 -07:00
parent 15c22d98c6
commit b0d8908724
11 changed files with 154 additions and 137 deletions

View File

@@ -0,0 +1,12 @@
import type { Dispatch, SetStateAction } from 'react';
import { useMemo, useState } from 'react';
import { debounce } from '../lib/debounce';
export function useDebouncedSetState<T extends string | number>(
defaultValue: T,
delay?: number,
): [T, Dispatch<SetStateAction<T>>] {
const [state, setState] = useState<T>(defaultValue);
const debouncedSetState = useMemo(() => debounce(setState, delay), [delay]);
return [state, debouncedSetState];
}