mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-05-16 04:37:22 +02:00
Split codebase (#455)
This commit is contained in:
12
packages/ui/src/hooks/useDebouncedState.ts
Normal file
12
packages/ui/src/hooks/useDebouncedState.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
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];
|
||||
}
|
||||
Reference in New Issue
Block a user