File "usePayPalScript.js"

Full Path: /home/siazco/grocery.siazco.se/wp-content/plugins/woocommerce-paypal-payments/modules/ppcp-applepay/resources/js/Block/hooks/usePayPalScript.js
File size: 699 bytes
MIME-type: text/x-java
Charset: utf-8

import { useState, useEffect } from '@wordpress/element';
import { loadPayPalScript } from '../../../../../ppcp-button/resources/js/modules/Helper/PayPalScriptLoading';

const usePayPalScript = ( namespace, ppcpConfig ) => {
	const [ isPayPalLoaded, setIsPayPalLoaded ] = useState( false );

	ppcpConfig.url_params.components += ',applepay';

	useEffect( () => {
		const loadScript = async () => {
			try {
				await loadPayPalScript( namespace, ppcpConfig );
				setIsPayPalLoaded( true );
			} catch ( error ) {
				console.error( `Error loading PayPal script: ${ error }` );
			}
		};

		loadScript();
	}, [ namespace, ppcpConfig ] );

	return isPayPalLoaded;
};

export default usePayPalScript;