diff --git a/plugins/woocommerce-blocks/assets/js/base/components/country-input/country-input.js b/plugins/woocommerce-blocks/assets/js/base/components/country-input/country-input.js index 92005abbb29..251a73b7cc1 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/country-input/country-input.js +++ b/plugins/woocommerce-blocks/assets/js/base/components/country-input/country-input.js @@ -1,6 +1,7 @@ /** * External dependencies */ +import { useMemo } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import PropTypes from 'prop-types'; import { decodeEntities } from '@wordpress/html-entities'; @@ -27,10 +28,14 @@ const CountryInput = ( { 'woo-gutenberg-products-block' ), } ) => { - const options = Object.keys( countries ).map( ( key ) => ( { - key, - name: decodeEntities( countries[ key ] ), - } ) ); + const options = useMemo( + () => + Object.keys( countries ).map( ( key ) => ( { + key, + name: decodeEntities( countries[ key ] ), + } ) ), + [ countries ] + ); return (
{ const countryStates = states[ country ]; - const options = countryStates - ? Object.keys( countryStates ).map( ( key ) => ( { - key, - name: decodeEntities( countryStates[ key ] ), - } ) ) - : []; + const options = useMemo( + () => + countryStates + ? Object.keys( countryStates ).map( ( key ) => ( { + key, + name: decodeEntities( countryStates[ key ] ), + } ) ) + : [], + [ countryStates ] + ); /** * Handles state selection onChange events. Finds a matching state by key or value.