重用库中的代码示例我的paypal按钮就像魅力一样,但现在我从这个组件中得到了这个警告:
警告:不建议通过主React包访问createClass, 并将在React v16.0中删除。使用纯JavaScript类 代替。如果您尚未准备好迁移,请创建-reaction-class v15。* 可在npm上作为临时替代品使用。有关更多信息 见printWarning @ lowPriorityWarning.js:38 lowPriorityWarning @ lowPriorityWarning.js:57 get @React.js:106 register @ checkout.lib.js:7165 Component.driver @ checkout.lib.js:5247 ./src/components/presentational/PayPalButton.js @ PayPalButton.js:6 的 webpack_require
因为问题是从第6行传来的,所以可能就是Button的创建方式:
const Button = paypal.Button.driver('react', { React, ReactDOM })
我尝试了警告中提供的this link,但没有多大帮助,我不知道如何导入或以不同方式创建它,这是我的完整代码:
import React from 'react'
import ReactDOM from 'react-dom'
import paypal from 'paypal-checkout'
import PropTypes from 'prop-types'
const Button = paypal.Button.driver('react', { React, ReactDOM })
export default class PayPalButton extends React.Component {
constructor(props) {
super(props)
this.state = {
env: this.props.env,
client: {
sandbox: this.props.sandboxID,
production: this.props.productionID
},
amount: this.props.amount,
currency: this.props.currency,
commit: this.props.commit
}
}
payment(data, actions) {
return actions.payment.create({
transactions: [
{
amount: { total: this.state.amount, currency: this.state.currency }
}
]
})
}
onAuthorize(data, actions) {
return actions.payment.execute().then((payment_data)=>{
var payment = {}
payment.paid = true
payment.cancelled = false
payment.payerID = data.payerID
payment.paymentID = data.paymentID
payment.paymentToken = data.paymentToken
payment.returnUrl = data.returnUrl
// getting buyer's shipping address and email
payment.address = payment_data.payer.payer_info.shipping_address
payment.email = payment_data.payer.payer_info.email
this.props.paymentDone(payment)
})
.catch(err => {
console.log ('error PayPal'+err)
throw err
})
}
render() {
return (
<Button
commit={ this.state.commit }
env={ this.state.env }
client={ this.state.client }
payment={ (data, actions) => this.payment(data, actions) }
onAuthorize={ (data, actions) => this.onAuthorize(data, actions) }
onCancel={this.props.onCancel}
onError = {this.props.onError}
/>
)
}
}
PayPalButton.propTypes = {
env: PropTypes.string.isRequired,
sandboxID: PropTypes.string,
productionID: PropTypes.string,
amount: PropTypes.number.isRequired,
currency: PropTypes.string.isRequired,
commit: PropTypes.bool.isRequired
}