Skip to content

Commit

Permalink
Use extracted useDebouncedInput hook
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Jun 21, 2023
1 parent 425759b commit e54aa4b
Showing 1 changed file with 1 addition and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import {
__unstableUseCompositeState as useCompositeState,
__unstableCompositeItem as CompositeItem,
} from '@wordpress/components';
import { useDebounce } from '@wordpress/compose';
import { useEntityRecords } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';

/**
* Internal dependencies
*/
import useDebouncedInput from '../../utils/use-debounced-input';
import { mapToIHasNameAndId } from './utils';

const EMPTY_ARRAY = [];
Expand Down Expand Up @@ -73,18 +73,6 @@ function SuggestionListItem( {
);
}

function useDebouncedInput() {
const [ input, setInput ] = useState( '' );
const [ debounced, setter ] = useState( '' );
const setDebounced = useDebounce( setter, 250 );
useEffect( () => {
if ( debounced !== input ) {
setDebounced( input );
}
}, [ debounced, input ] );
return [ input, setInput, debounced ];
}

function useSearchSuggestions( entityForSuggestions, search ) {
const { config } = entityForSuggestions;
const query = useMemo(
Expand Down

0 comments on commit e54aa4b

Please sign in to comment.