问题
I have this code that is supposed to render the paypal buttons.
<Head>
<script src="https://www.paypal.com/sdk/js?client-id=KEY"></script>
</Head>
I load the paypal buttons in the componentDidMount method
componentDidMount() {
paypal
.Buttons({
createOrder: (data, actions)=> {
return actions.order.create({
purchase_units: [{
amount: {
currency_code: "USD",
value: amount,
},
}],
});
},
onCancel: function(data){
//console.log(data)
},
onError: function(err){
console.log(err)
}
})
.render("#paypal");
}
<div id="paypal" className=""></div>
on first page load the page throws an error that paypal is not defined i am guessing because the script is not loaded fully when the componentDidMount method is called. How can I wait until the script is loaded for the buttons to be rendered properly
来源:https://stackoverflow.com/questions/61778707/wait-for-loading-paypal-script-in-nextjs-page