mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-18 23:43:55 +01:00
Refactor debounce and tauri event listeners
This commit is contained in:
12
src-web/hooks/useDebouncedSetState.ts
Normal file
12
src-web/hooks/useDebouncedSetState.ts
Normal 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];
|
||||
}
|
||||
Reference in New Issue
Block a user