UNPKG

@wordpress/compose

Version:
26 lines (24 loc) 794 B
/** * WordPress dependencies */ import { useEffect, useState } from '@wordpress/element'; /** * Internal dependencies */ import useDebounce from '../use-debounce'; /** * Helper hook for input fields that need to debounce the value before using it. * * @param defaultValue The default value to use. * @return The input value, the setter and the debounced input value. */ export default function useDebouncedInput(defaultValue = '') { const [input, setInput] = useState(defaultValue); const [debouncedInput, setDebouncedState] = useState(defaultValue); const setDebouncedInput = useDebounce(setDebouncedState, 250); useEffect(() => { setDebouncedInput(input); }, [input, setDebouncedInput]); return [input, setInput, debouncedInput]; } //# sourceMappingURL=index.js.map