Optimize for prop drilling

This commit is contained in:
Daniel Dudzic 2024-09-13 23:09:51 +02:00
parent f77aae6b90
commit 859fd3396b
No known key found for this signature in database
GPG key ID: 31B40D33E3465483
6 changed files with 28 additions and 43 deletions

View file

@ -3,8 +3,6 @@ import { registerPaymentMethod } from '@woocommerce/blocks-registry';
// Hooks
import useFastlaneSdk from './hooks/useFastlaneSdk';
import useCustomerData from './hooks/useCustomerData';
import useShippingAddressChange from './hooks/useShippingAddressChange';
import useCardChange from './hooks/useCardChange';
import useAxoSetup from './hooks/useAxoSetup';
import usePaymentSetup from './hooks/usePaymentSetup';
@ -22,39 +20,17 @@ const Axo = ( props ) => {
const [ shippingAddress, setShippingAddress ] = useState( null );
const [ card, setCard ] = useState( null );
const fastlaneSdk = useFastlaneSdk( axoConfig, ppcpConfig );
const {
shippingAddress: wooShippingAddress,
billingAddress: wooBillingAddress,
setShippingAddress: updateWooShippingAddress,
setBillingAddress: updateWooBillingAddress,
} = useCustomerData();
const onChangeShippingAddressClick = useShippingAddressChange(
fastlaneSdk,
setShippingAddress,
updateWooShippingAddress
);
const onChangeCardButtonClick = useCardChange(
fastlaneSdk,
setCard,
updateWooBillingAddress
);
const onChangeCardButtonClick = useCardChange( fastlaneSdk, setCard );
useAxoSetup(
ppcpConfig,
fastlaneSdk,
wooShippingAddress,
wooBillingAddress,
updateWooShippingAddress,
updateWooBillingAddress,
onChangeShippingAddressClick,
onChangeCardButtonClick,
setShippingAddress,
setCard
);
usePaymentSetup( onPaymentSetup, emitResponse, card );
useAxoCleanup( updateWooShippingAddress, updateWooBillingAddress );
useAxoCleanup();
const handlePaymentLoad = useCallback( ( paymentComponent ) => {
console.log( 'Payment component loaded', paymentComponent );