Skip to content

Commit

Permalink
Revert debounce input
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Jul 2, 2024
1 parent f57bf39 commit 0c3b9a0
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions packages/dataviews/src/dataform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
*/
import { __ } from '@wordpress/i18n';
import { TextControl } from '@wordpress/components';
import { useEffect, useMemo } from '@wordpress/element';
import { useDebouncedInput } from '@wordpress/compose';
import { useCallback, useMemo } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -31,23 +30,23 @@ function DataFormTextControl< Item >( {
onUpdate,
}: DataFormTextControlProps< Item > ) {
const { id, header, placeholder } = field;
const [ value, setValue, debouncedValue ] = useDebouncedInput(
field.getValue( { item: data } )
);
const value = field.getValue( { item: data } );

useEffect( () => {
onUpdate( ( prevItem: any ) => ( {
...prevItem,
[ id ]: debouncedValue,
} ) );
}, [ debouncedValue ] );
const onChange = useCallback(
( newValue: string ) =>
onUpdate( ( prevItem: any ) => ( {
...prevItem,
[ id ]: newValue,
} ) ),
[ id, onUpdate ]
);

return (
<TextControl
label={ header }
placeholder={ placeholder }
value={ value }
onChange={ setValue }
onChange={ onChange }
/>
);
}
Expand Down

0 comments on commit 0c3b9a0

Please sign in to comment.