首页 > 解决方案 > 'getPastEvents' 没有响应

问题描述

交互.js

export const loadAllOrders = async (exchange, dispatch) => {
  // Fetch cancelled orders with the "Cancel" event stream
  const cancelStream = await exchange.getPastEvents('Cancel', { fromBlock: 0, toBlock: 'latest' })
  console.log(cancelStream)
}

但是这样的错误 在此处输入图像描述

我不知道是什么问题

如果你知道请帮忙

对不起加上 Content.js

import React, { Component } from 'react'
import { connect } from 'react-redux'
import { exchangeSelector } from '../store/selectors'
import { loadAllOrders } from '../store/interactions'

class Content extends Component {
  componentWillMount() {
    this.loadBlockchainData(this.props.dispatch)
  }

  async loadBlockchainData(dispatch) {
    await loadAllOrders(this.props.exchange, dispatch)
  }
 ~~~

function mapStateToProps(state) {
  return {
    exchange: state.exchangeSelector
  }
}

export default connect(mapStateToProps)(Content)

加上新代码

标签: reactjs

解决方案


无法读取未定义的属性“getPastEvents”。这意味着exchangeundefined您调用 function 时loadAllOrders

async loadBlockchainData(dispatch) {
    await loadAllOrders(this.props.exchange, dispatch)
    // You can not direct access to this.props with function in Class
    // this.props just direct shaft access only in life cycle and render
}

所以,你必须loadBlockchainData像这样传递参数:

async loadBlockchainData(exchange, dispatch) {
    await loadAllOrders(exchange, dispatch)
}

在渲染中调用这个函数:

this.loadBlockchainData(this.props.exchange)

推荐阅读