mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
26 lines
630 B
JavaScript
26 lines
630 B
JavaScript
import { useState, useEffect } from '@wordpress/element';
|
|
|
|
const useGooglepayConfig = ( namespace, isGooglepayLoaded ) => {
|
|
const [ googlePayConfig, setGooglePayConfig ] = useState( null );
|
|
|
|
useEffect( () => {
|
|
const fetchConfig = async () => {
|
|
if ( ! isGooglepayLoaded ) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const config = await window[ namespace ].Googlepay().config();
|
|
setGooglePayConfig( config );
|
|
} catch ( error ) {
|
|
console.error( 'Failed to fetch Google Pay config:', error );
|
|
}
|
|
};
|
|
|
|
fetchConfig();
|
|
}, [ namespace, isGooglepayLoaded ] );
|
|
|
|
return googlePayConfig;
|
|
};
|
|
|
|
export default useGooglepayConfig;
|