无法访问 onToken 函数中的道具

Can't access props within onToken function

伙计们,我正在使用 react-stripe-checkout 来收集我用户的信用卡信息。在收集了用户的详细信息并将它们发送到我的后端后,我试图从 this.props 调用一个函数来更新状态客户端,但是 'this' 没有可用的 props/state。查看图像以查看 onToken 函数中 'this' 的范围。有没有办法在 onToken 中访问 props 或 class 函数(例如 onTokenThen)?

import React, { Component } from 'react';
import StripeCheckout from 'react-stripe-checkout';
import { Button } from 'react-bootstrap';
import Axios from 'axios';

export default class AddCustomer extends Component {
  constructor (props, context){
    super(props, context);
    this.onTokenThen = this.onTokenThen.bind(this);
  };

  onToken(token) {
    console.log('token', token);
    debugger; // <-- 'this' 
    Axios({
      method: 'post',
      url: '/api/v1/addCustomer',
      data: {
        stripeToken: token
      }
    })
    .then(this.props.addCustomerState) // <-- can't access props here
    .catch(function (response) {
      console.log(response);
    });
  }

  onTokenThen(customer){
    debugger;
  }

  render() {
    let currentUser = this.props.activeUser.email;
    return (
        <StripeCheckout
          ...
          token={this.onToken}
          ...
          <Button bsStyle="success">
            Add customer
          </Button>
        </StripeCheckout>
    );
  }
};

在构造函数中将onToken函数绑定到'this'解决了问题;令牌和 props/class 功能现已可用。

  constructor (props, context){
    super(props, context);
    this.onToken = this.onToken.bind(this); // <-- makes available 'this' in onToken scope
  };