import { type AnyFunction, type DebouncedFunction } from "./types.js"; /** * Creates a function that will only be called if it has not been called again * for X milliseconds. * * @example Debounced Search API Requests * ```tsx * import { TextField } from "@react-md/core/form/TextField"; * import { useDebouncedFunction } from "@react-md/core/useDebouncedFunction"; * import { useUnmounted } from "@react-md/core/useUnmounted"; * import { useState } from "react"; * import type { ReactElement } from "react"; * * interface State { * error?: unknown * loading: boolean; * results?: { * // pretend some search results * id: string; * name: string; * }[]; * } * * function Example(): ReactElement { * const [state, setState] = useState({ * loading: false, * }); * // this is only required for async actions * const unmounted = useUnmounted(); * * // A new search request will be fired once every 500ms as the user types. * // can't use the event here since React uses synthetic events * const search = useDebouncedFunction(async (q: string) => { * setState({ * loading: true, * error: undefined, * results: undefined, * }); * * try { * const response = await fetch('/search', { * method: 'POST', * headers: { * 'Content-Type': 'application/json', * }, * body: JSON.stringify({ q }), * }); * const json = await response.json(); * * if (!unmounted.current) { * setState({ * loading: false, * results: json, * }); * } * } catch (error) { * if (!unmounted.current) { * setState({ * error, * loading: false, * }); * } * } * }, 500); * * return ( * search(event.currentTarget.value)} * /> * ); * } * ``` * * @see `useThrottledFunction` for throttle behavior instead. (Call a * function at most once every X milliseconds). * @since 6.0.0 */ export declare function useDebouncedFunction(func: F, wait: number): DebouncedFunction;