Skip to content

Commit

Permalink
Apply update from Code Review
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Oct 5, 2023
1 parent 82aeb6f commit 1e9288f
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
*/
import { useState } from '@wordpress/element';

/**
* External dependencies
*/
import fastDeepEqual from 'fast-deep-equal';

export default function useInternalValue( value ) {
const [ internalValue, setInternalValue ] = useState( value || {} );
const [ previousValue, setPreviousValue ] = useState( value );
Expand All @@ -11,11 +16,9 @@ export default function useInternalValue( value ) {
// See:
// - https://github.com/WordPress/gutenberg/pull/51387#issuecomment-1722927384.
// - https://react.dev/reference/react/useState#storing-information-from-previous-renders.
if ( value !== previousValue ) {
if ( ! fastDeepEqual( value, previousValue ) ) {
setPreviousValue( value );
if ( value !== internalValue ) {
setInternalValue( value );
}
setInternalValue( value );
}

const setInternalURLInputValue = ( nextValue ) => {
Expand Down

0 comments on commit 1e9288f

Please sign in to comment.