import { useEffect, useState } from "react" /** Hook to debounce a state. Returns normal value and setter and a third, debounced output */ export function useDebouncedState(initialValue: T, delay: number): [T, (value: T) => void, T] { const [value, setValue] = useState(initialValue) const [debouncedValue, setDebouncedValue] = useState(initialValue) useEffect(() => { const timeout = setTimeout(() => setDebouncedValue(value), delay) return () => clearTimeout(timeout) }, [value]) return [value, setValue, debouncedValue] }