mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
26 lines
619 B
JavaScript
26 lines
619 B
JavaScript
import { useState, useEffect } from '@wordpress/element';
|
|
|
|
const useApplepayConfig = ( namespace, isApplepayLoaded ) => {
|
|
const [ applePayConfig, setApplePayConfig ] = useState( null );
|
|
|
|
useEffect( () => {
|
|
const fetchConfig = async () => {
|
|
if ( ! isApplepayLoaded ) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const config = await window[ namespace ].Applepay().config();
|
|
setApplePayConfig( config );
|
|
} catch ( error ) {
|
|
console.error( 'Failed to fetch Apple Pay config:', error );
|
|
}
|
|
};
|
|
|
|
fetchConfig();
|
|
}, [ namespace, isApplepayLoaded ] );
|
|
|
|
return applePayConfig;
|
|
};
|
|
|
|
export default useApplepayConfig;
|