现在在这里解决问题之后 REDUX - How to import an API function return Promise and add it into payload on action creator
我有以下错误:
错误:操作必须是普通对象。使用自定义中间件进行异步操作。▶ 3 个堆栈帧被折叠。App.componentWillMount src/component/App.js:18 15 | 16 | 17 | 组件WillMount() {
18 | 常量数据 = this.props.fetchBetList(); 19 | this.setState({ items: data }) 20 | 21 | 查看编译 ▶ 24 个堆栈帧被折叠。./src/index.js src/index.js:31 28 |
29 | 常量 createStoreWithMiddleware = applyMiddleware(ReduxPromise)(createStore); 30 | 31 | ReactDOM.render( 32 | 33 | 34 | 查看已编译 ▶ 6 个堆栈帧已折叠。此屏幕仅在开发中可见。如果应用程序在生产中崩溃,则不会出现。打开浏览器的开发者控制台以进一步检查此错误。
import React, { Component } from 'react';
import BetList from './BetList';
import './App.css';
import items from '../data/betItems.json';
import { connect } from 'react-redux';
import { fetchBetList, fetchLatestPrices } from '../actions/index';
class App extends Component {
constructor(props) {
super(props);
this.state = {
items: []
}
}
componentWillMount() {
const data = this.props.fetchBetList();
this.setState({ items: data })
}
render() {
return (
<div className="App">
<h1>Tottenham Hotspur v Manchester City</h1>
<h2>Correct Score</h2>
<BetList items={this.state.items} />
</div>
);
}
}
export default connect(null, { fetchBetList, fetchLatestPrices })(App);
我试图获得已解决的 Promise 并使用生命周期方法来更新 state.items....