atk*_*yla 1 stripe-payments typescript reactjs
我在输入this.props.stripe. 我不确定我需要把什么类型放在那里。
@types/react-stripe-elements 已安装。
<StripeProvider apiKey="xxx">
<div className="example">
<h1>React Stripe Elements Example</h1>
<Elements>
<CheckoutForm />
</Elements>
</div>
</StripeProvider>
Run Code Online (Sandbox Code Playgroud)
import React from 'react';
import {CardElement, injectStripe } from 'react-stripe-elements';
type CheckoutFormProps = {
stripe: StripeProps
}
class CheckoutForm extends React.Component<CheckoutFormProps, {}> {
submit = async (ev: React.SyntheticEvent) => {
// User clicked submit
let {token} = await this.props.stripe.createToken({name: "Name"});
console.log(token);
}
render() {
return (
<div className="checkout">
<p>Would you like to complete the purchase?</p>
<CardElement />
<button onClick={this.submit}>Purchase</button>
</div>
);
}
}
export default injectStripe(CheckoutForm);
Run Code Online (Sandbox Code Playgroud)
错误: Cannot find name 'StripeProps.
我也试过了InjectedStripeProps。
导入命名空间ReactStripeElements来自react-stripe-elements:
import { ReactStripeElements } from 'react-stripe-elements'
Run Code Online (Sandbox Code Playgroud)
然后就可以引用接口了:
ReactStripeElements.StripeProps
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
791 次 |
| 最近记录: |