UNPKG

@wojtekmaj/react-hooks

Version:

A collection of React Hooks.

16 lines (15 loc) 661 B
import { 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(initialValue, debounceTime = 250) { const [value, setValue] = useState(initialValue); const debouncedValue = useDebouncedValue(value, debounceTime); return [debouncedValue, setValue]; }