️ 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 { CheckboxStylingSection } from '../Layout';
import { useMemo } from '@wordpress/element';
const SectionPaymentMethods = ( { location } ) => {
const { paymentMethods, setPaymentMethods, choices } =
StylingHooks.usePaymentMethodProps( location );
const { all: allMethods } = PaymentHooks.usePaymentMethods();
const filteredChoices = choices.filter( ( choice ) => {
const methodConfig = allMethods.find( ( i ) => i.id === choice.value );
return methodConfig?.enabled;
} );
const filteredChoices = useMemo( () => {
return choices.filter( ( choice ) => {
const methodConfig = allMethods.find(
( i ) => i.id === choice.value
);
return methodConfig?.enabled;
} );
}, [ choices, allMethods ] );
return (
<CheckboxStylingSection