简体   繁体   English

动作必须是普通对象。 使用自定义中间件

[英]Action must be plain object. Use custom middleware

What would be the problem? 有什么问题吗?

Uncaught Error: Actions must be plain objects. 未捕获的错误:动作必须是普通对象。 Use custom middleware for async actions. 使用自定义中间件进行异步操作。

Configure Store: 配置商店:

export default configureStore = () => {
  let store = compose(applyMiddleware(ReduxThunk))(createStore)(reducers);
  return store;
}

Action 行动

export const menulist = async ({ navigation  }) => {
  return async dispatch => {
    try {
        dispatch({ type: types.MENULIST_REQUEST_START })
        let response = await menuListByCategories();
        dispatch({ type: types.MENULIST_SUCCESS })
    } catch (error) {
        dispatch({ type: types.MENULIST_FAILED })
    }
  }
}

You are using it the wrong way, 您使用错误的方式,

in Redux every action must return an object, and this is a must! 在Redux中,每个动作都必须返回一个对象,这是必须的! so, your dispatch, which is a function, should be called this way. 因此,应以这种方式调用作为函数的调度。

Besides you only need to declare async the function which returns dispatch. 此外,您只需要声明异步返回派遣的功能。 The async keyword determines that the following function will return a promise. async关键字确定以下函数将返回承诺。 As your first function (menulist) is returning the promise returned by the second function (dispatch one) you don't have to specify it. 当您的第一个函数(菜单员)返回第二个函数(调度一个)返回的promise时,您不必指定它。

export const menulist = ({ navigation  }) => async (dispatch) => {
    try {
        dispatch({ type: types.MENULIST_REQUEST_START })
        let response = await menuListByCategories();

        dispatch({ type: types.MENULIST_SUCCESS })
    } catch (error) {
        dispatch({ type: types.MENULIST_FAILED })
    }
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 异步操作 Redux 未处理拒绝(错误):操作必须是普通对象。 使用自定义中间件进行异步操作 - Async Action Redux Unhandled Rejection (Error): Actions must be plain objects. Use custom middleware for async actions 未捕获的错误:操作必须是普通对象。 使用自定义中间件 - Uncaught Error: Actions must be plain objects. Use custom middleware 使用自定义中间件进行异步操作。 动作必须是普通对象 - Use custom middleware for async actions. Actions must be plain objects 动作必须是普通对象。 使用自定义中间件进行异步操作。 通过使用中间件 - Actions must be plain objects. Use custom middleware for async actions. by using middleware 反应:行动必须是简单的 Object - React : Action Must Be Plain Object 错误 - 操作必须是普通对象。 使用自定义中间件进行异步操作 - Error - Actions must be plain objects. Use custom middleware for async actions 错误服务器错误:操作必须是普通对象。 使用自定义中间件进行异步操作 - Error server Error: Actions must be plain objects. Use custom middleware for async actions 错误:动作必须是普通对象。 使用自定义中间件进行异步操作。 React-redux错误 - Error: Actions must be plain objects. Use custom middleware for async actions. React-redux error React-Redux:动作必须是普通对象。 使用自定义中间件进行异步操作错误 - React-Redux: Actions must be plain objects. Use custom middleware for async actions Error react-redux 错误:操作必须是普通对象。 使用自定义中间件进行异步操作 - react-redux Error: Actions must be plain objects. Use custom middleware for async actions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM