woocommerce-paypal-payments/modules/ppcp-googlepay/resources/js/Block/components/GooglepayButton.js

32 lines
693 B
JavaScript
Raw Normal View History

2024-10-09 16:38:11 +02:00
import { useState, useEffect } from '@wordpress/element';
import useGooglepayApiToGenerateButton from '../hooks/useGooglepayApiToGenerateButton';
const GooglepayButton = ( {
namespace,
buttonConfig,
ppcpConfig,
googlepayConfig,
} ) => {
const [ buttonHtml, setButtonHtml ] = useState( '' );
const googlepayButton = useGooglepayApiToGenerateButton(
namespace,
buttonConfig,
ppcpConfig,
googlepayConfig
);
useEffect( () => {
if ( googlepayButton ) {
setButtonHtml( googlepayButton.outerHTML );
}
}, [ googlepayButton ] );
if ( ! buttonHtml ) {
return null;
}
return <div dangerouslySetInnerHTML={ { __html: buttonHtml } } />;
};
export default GooglepayButton;