【问题标题】:actions must be plain objects. use custom middleware for async actions, firebase, redux, redux-thunk动作必须是普通对象。为异步操作、firebase、redux、redux-thunk 使用自定义中间件
【发布时间】:2019-03-29 06:16:33
【问题描述】:

ios 虚拟机上的错误消息行:操作必须是普通对象。使用自定义中间件进行异步操作。 我注意到 upLoadImageToFirebase() 存在问题。 我在使用 redux 和 firebase 时遇到了这个问题。有人能帮我吗?非常感谢!

"react-redux": "^6.0.1",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0"
"react-native": "0.58.006",
upLoadImageToFirebase = (item) => {
    return storage.ref('imgProduct').child(`${item.key}.jpg`)
        .put(item.blob, { contentType: 'application/octet-stream' })
}

export const addProduct = (product) => {
    return (dispatch) => {
        let { blobs } = product;
        let urls = [];
        dispatch(startAdd());
        blobs.forEach((item) => {
            dispatch(upLoadImageToFirebase(item)).then((snapshoot) => {
                urls = urls.concat(snapshoot.ref.getDownloadURL());
            }).catch(err => {
            console.log(err)
        })
        })
    }
}

【问题讨论】:

  • 您可以添加您的商店设置吗?第二次调度也应该调度类似{ type: 'MY_ACTION_TYPE', payload: someData }
  • 请发布您的src/index.js 文件和actions/index.js 文件,除非您告诉我上面的内容是您的动作创建者,不清楚。

标签: firebase react-native redux react-redux


【解决方案1】:

我可以看到你正在使用 redux-thunk。检查您是否也在中间件中添加了它。

【讨论】:

  • 我将 applyMiddleware (thunk) 添加到项目中的商店。
猜你喜欢
  • 1970-01-01
  • 2017-11-16
  • 2018-05-09
  • 2019-03-04
  • 2020-06-13
  • 2018-03-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多