woocommerce-paypal-payments/modules/ppcp-axo-block/resources/js/hooks/usePaymentSetupEffect.js
Philipp Stracker 243630ea5d
🐛 Revert logic to call setPaymentComponent
Before the change, the paymentComponent always was null, as it was not set anywhere.
2024-09-16 15:45:41 +02:00

30 lines
719 B
JavaScript

import { useEffect, useCallback } from '@wordpress/element';
const usePaymentSetupEffect = (
onPaymentSetup,
handlePaymentSetup,
setPaymentComponent
) => {
/**
* `onPaymentSetup()` fires when we enter the "PROCESSING" state in the checkout flow.
* It pre-processes the payment details and returns data for server-side processing.
*/
useEffect( () => {
const unsubscribe = onPaymentSetup( handlePaymentSetup );
return () => {
unsubscribe();
};
}, [ onPaymentSetup, handlePaymentSetup ] );
const handlePaymentLoad = useCallback(
( component ) => {
setPaymentComponent( component );
},
[ setPaymentComponent ]
);
return { handlePaymentLoad };
};
export default usePaymentSetupEffect;