Better GraphQL schema fetching

This commit is contained in:
Gregory Schier
2023-04-01 17:53:36 -07:00
parent 9cbe24e740
commit 11a89f06c1
6 changed files with 101 additions and 50 deletions

View 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;
}