woocommerce-paypal-payments/modules/ppcp-axo-block/resources/js/hooks/usePaymentSetupEffect.js

31 lines
719 B
JavaScript
Raw Normal View History

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;