Skip to content

Commit

Permalink
Reinstate state “reset” but avoid passing internalInputValue as dep t…
Browse files Browse the repository at this point in the history
…o effect
  • Loading branch information
getdave committed Mar 31, 2023
1 parent dc703a7 commit 029caff
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';
import { useState, useEffect } from '@wordpress/element';

export default function useInternalInputValue( value ) {
const [ internalInputValue, setInternalInputValue ] = useState(
value || ''
);

// If the value prop changes, update the internal state.
useEffect( () => {
setInternalInputValue( ( prevValue ) => {
if ( value && value !== prevValue ) {
return value;
}

return prevValue;
} );
}, [ value ] );

return [ internalInputValue, setInternalInputValue ];
}

0 comments on commit 029caff

Please sign in to comment.