react-redux - Redux 说要在行动中使用普通对象。但不知道在哪里使用普通对象
问题描述
我在 SO 中寻找我的答案,但找不到任何合适的答案。所以在这里我带着我的问题去......
在我的 redux 操作创建器中,我正在从中获取 API 调用,isomorphic-unfetch
但我Error: Actions must be plain objects. Use custom middleware for async actions
每次都收到消息。虽然我dispatch
在我的操作中定义了......
我的操作代码是
const exchangeBuy = ({btc, usdt, id}, url) => {
return (dispatch) => {
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify( { btc, usdt, id } )
}).then(
r => r.json()
).then(
r => dispatch({
type: 'EXCHANGE_BUY',
payload: r //here r return an object from mongoDB
})
)
}
}
调用它的代码也是
submitExchange(e){
e.preventDefault()
const btc = e.target.btcamount.value
const usdt = e.target.usdprice.value
this.props.exchangeBuy( //Here it is
{
btc: btc,
usdt: usdt,
id: this.props.users.id
},
this.props.apiurl )
}
解决方案
推荐阅读
- ruby-on-rails - GrapeSwagger::Errors::UnregisteredParser:没有为字符串注册解析器
- dynamics-crm - 保存文档和报价出现 Dynamics CRM 2015
- go - Go 编译器:错误行号不正确,给出 1048575 即 0xFFFFF,当问题在文件中进一步出现时
- c++ - CMake 无法链接外部库
- java - 如何在 logback 中的应用程序关闭时滚动日志文件?
- angular - 违规点击处理程序采用 angular 5 和 chrome zone.js
- python - 来自元组的 Pandas 数据帧 MultiIndex 附加到 HDF5 无法匹配现有表结构
- rest - 我可以为 WaypointParameterType 使用邮政编码吗?
- javascript - 如何将 Kotlin Javascripts“Date::toLocaleDateString”与“LocaleOptions”一起使用?
- javascript - 打开行选择对话框 [材料表]