mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-05 00:37:04 +02:00
Better GraphQL schema fetching
This commit is contained in:
13
src-web/hooks/useDebouncedValue.ts
Normal file
13
src-web/hooks/useDebouncedValue.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
|
||||
export function useDebouncedValue<T extends string | number>(value: T, delay = 1000) {
|
||||
const [state, setState] = useState<T>(value);
|
||||
const timeout = useRef<NodeJS.Timeout>();
|
||||
|
||||
useEffect(() => {
|
||||
clearTimeout(timeout.current ?? 0);
|
||||
timeout.current = setTimeout(() => setState(value), delay);
|
||||
}, [value, delay]);
|
||||
|
||||
return state;
|
||||
}
|
||||
Reference in New Issue
Block a user