【发布时间】:2021-02-17 22:35:04
【问题描述】:
Stripe Payment 完全可用,但我在控制台上收到警告消息,“Elements 上的道具更改不受支持:设置后您无法更改 stripe 道具。”
这是我的代码。我不知道为什么会显示警告消息,我错过了什么?
const Parent =() => {
const stripePromise = loadStripe(PUBLISHABLE_KEY);
<Elements stripe ={stripePromise}>
<Child_component/>
</Elements>
}
export default Parent;
import {CardNumberElement, CardExpiryElement, CardCvcElement} from '@stripe/react-stripe-js';
const Child_component =() => {
const handleChange = (event) => {
//get the brand type
};
const handleFormSubmit = async ev =>{
const cardElement = elements.getElement(CardNumberElement);
const paymentMethodReq = await stripe.createPaymentMethod({
type: 'card',
card: cardElement
});
/// and send paymentMethodReq to the backend.
}
render(
<Form className="" onSubmit={handleFormSubmit}>
<div className="split-form full-width inline-block pt-4">
<div className="row">
<div className="col-12">
<label className="card-element">
Card number
<CardNumberElement
className="cardNumberElement"
onChange={handleChange}
/>
</label>
</div>
<div className="col-8">
<label className="card-element">
Expiration date
<CardExpiryElement
onChange={handleChange}
/>
</label>
</div>
<div className="col-4">
<label className="card-element">
CVC
<CardCvcElement
onChange={handleChange}
/>
</label>
</div>
</div>
</div>
</Form>
)
}
export default Child_component;
【问题讨论】:
-
你能证明你的完整组件吗?不清楚你在哪里使用它
-
@NikitaChayka 我更新了我的代码,请检查。谢谢!
标签: reactjs stripe-payments next.js