Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/wojtekmaj/react-hooks. A collection of React Hooks.
hooks react react-hooks
Something went wrong. Try again.
718 B · 22 lines
TypeScript
at main
1234567891011121314151617181920212223import { useState } from 'react';
import useDebouncedValue from './useDebouncedValue.js';
/** * Returns a debounced state and a function to update it. * * @template T * @param {T} initialValue The initial value of the state * @param {number} [debounceTime=250] The delay to wait before updating the state * @returns {[T, React.Dispatch<React.SetStateAction<T>>]} The debounced state and a function to update it */export default function useDebouncedState<T>( initialValue: T, debounceTime = 250,): [T, React.Dispatch<React.SetStateAction<T>>] { const [value, setValue] = useState(initialValue);
const debouncedValue = useDebouncedValue(value, debounceTime);
return [debouncedValue, setValue];}