Skip to content

Commit

Permalink
Enhance Site Editor's use-debounced-input hook
Browse files Browse the repository at this point in the history
  • Loading branch information
WunderBart committed Aug 2, 2023
1 parent 1889ccd commit c310883
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/edit-site/src/utils/use-debounced-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { useDebounce } from '@wordpress/compose';

export default function useDebouncedInput( defaultValue = '' ) {
const [ input, setInput ] = useState( defaultValue );
const [ debounced, setter ] = useState( defaultValue );
const setDebounced = useDebounce( setter, 250 );
const [ debouncedInput, setDebouncedState ] = useState( defaultValue );

const setDebouncedInput = useDebounce( setDebouncedState, 250 );

useEffect( () => {
if ( debounced !== input ) {
setDebounced( input );
}
}, [ debounced, input ] );
return [ input, setInput, debounced ];
setDebouncedInput( input );
}, [ input ] );

return [ input, setInput, debouncedInput ];
}

0 comments on commit c310883

Please sign in to comment.