️ Memoize payment methods in styling tab

This commit is contained in:
Philipp Stracker 2025-02-13 15:27:29 +01:00
parent 30ff337c06
commit 16ec522830
No known key found for this signature in database

View file

@ -2,17 +2,21 @@ import { __ } from '@wordpress/i18n';
import { PaymentHooks, StylingHooks } from '../../../../../../data'; import { PaymentHooks, StylingHooks } from '../../../../../../data';
import { CheckboxStylingSection } from '../Layout'; import { CheckboxStylingSection } from '../Layout';
import { useMemo } from '@wordpress/element';
const SectionPaymentMethods = ( { location } ) => { const SectionPaymentMethods = ( { location } ) => {
const { paymentMethods, setPaymentMethods, choices } = const { paymentMethods, setPaymentMethods, choices } =
StylingHooks.usePaymentMethodProps( location ); StylingHooks.usePaymentMethodProps( location );
const { all: allMethods } = PaymentHooks.usePaymentMethods(); const { all: allMethods } = PaymentHooks.usePaymentMethods();
const filteredChoices = choices.filter( ( choice ) => { const filteredChoices = useMemo( () => {
const methodConfig = allMethods.find( ( i ) => i.id === choice.value ); return choices.filter( ( choice ) => {
return methodConfig?.enabled; const methodConfig = allMethods.find(
} ); ( i ) => i.id === choice.value
);
return methodConfig?.enabled;
} );
}, [ choices, allMethods ] );
return ( return (
<CheckboxStylingSection <CheckboxStylingSection