reactjs - '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)
加上新代码
解决方案
无法读取未定义的属性“getPastEvents”。这意味着exchange
当undefined
您调用 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)
推荐阅读
- command-line-interface - 如何使用 ubuntu 终端在特定应用程序中打开文件
- python - 如何在 pandas 中查找单词?还是两个词的组合?
- intellij-idea - IntelliJ 自动格式化 Ctrl+Alt+L 符号问题
- c# - 如何用获得的像素颜色绘制面板?
- continuous-integration - 如何在gitlab中使用不同图像的作业之间共享环境变量?
- c++ - ZMQ:当没有订阅者时,消息是否在扩展的 pub-sub 中发布?
- sublimetext3 - 如何使用 Julia 在 sublime 文本上添加横幅评论
- r - 将 .SD 与重命名的变量与 .SD 列的名称相结合
- filter - Neo4j:基于属性列表进行过滤的 Cypher
- python - 如何从字母字符串中制作字母列表