mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
30 lines
719 B
JavaScript
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;
|