【问题标题】:The function call inside the redux action doesnot get executedredux action 中的函数调用没有被执行
【发布时间】:2020-06-10 14:54:15
【问题描述】:

我正在尝试我的第一个使用 redux 的反应应用程序,以及作为中间件的 Thunk。从其中一个组件调用动作时,会触发动作,但不会执行动作返回中的代码。我不知道我在这里缺少什么。我也在使用 Firestore 来获取数据。

    export const getBikeTypes = () => {
    console.log('outside return')
    return (dispatch, getState, { getFireBase, getFireStore }) => {
        console.log('inside return')
        const firestore = getFireStore();
        firestore.collection('BikeTypes').get()
            .then((response) => {
                console.log(response)
                return response
            }).then(() => {
                dispatch({ type: 'GET_BIKETYPES' });
            }).catch((err) => {
                dispatch({ type: 'GET_BIKETYPES_FAIL', err });
            })
    }
};

【问题讨论】:

  • 您能分享一下您将 thunk 中间件连接到商店的配置代码吗?
  • 你能解释一下你所说的行动是什么意思吗?你能看到“内部返回”和响应console.logs吗?

标签: reactjs redux google-cloud-firestore thunk


【解决方案1】:

我认为您应该在收到响应后使用有效负载发送操作。

const firestore = getFireStore();
firestore.collection('BikeTypes').get()
  .then((response) => {
     dispatch({ type: 'GET_BIKETYPES', payload: response })
  })

【讨论】:

    猜你喜欢
    • 2016-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 2012-05-12
    • 1970-01-01
    • 2017-03-23
    • 1970-01-01
    相关资源
    最近更新 更多