Печатание реквизита для компонента, вводимого Stripe - PullRequest
0 голосов
/ 29 сентября 2019

У меня проблемы с набором текста для this.props.stripe. Я не уверен, какой тип мне нужно поставить.

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-stripe-elements/index.d.ts#L44

@types/react-stripe-elements установлено.

        <StripeProvider apiKey="xxx">
            <div className="example">
                <h1>React Stripe Elements Example</h1>
                <Elements>
                    <CheckoutForm />
                </Elements>
            </div>
        </StripeProvider>

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);

Ошибка: Cannot find name 'StripeProps.

Я также пытался InjectedStripeProps.

1 Ответ

0 голосов
/ 16 октября 2019

Импорт пространства имен ReactStripeElements из react-stripe-elements:

import { CardElement, injectStripe, ReactStripeElements } from 'react-stripe-elements'

Затем вы можете ссылаться на интерфейс:

ReactStripeElements.StripeProps
...