首页 > 解决方案 > 获取 Actions 必须是 react native redux 中的普通对象

问题描述

嗨,我收到了错误Error: Actions must be plain objects. Use custom middleware for async actions.,但我正在使用 redux-thunk,并且我已经对正在使用的异步调用进行了一些操作。有人知道我为什么会收到此错误吗?

export function reportUser(userId, idBlocked, raisons) {
  return function (dispatch) {
    return axios({
      url: url,
      method: 'post',
      data: {
        id: userId,
        membres_id: idBlocked,
        raisons: raisons,
      },
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
      },
    })
      .then(function (response) {
        dispatch({ type: 'SET_REPORT_USER', payload: response.data });
        console.log(response.data);
        setTimeout(() => {
          Alert.alert('Le membre a bien été débloqué.');
        }, 500); // Wait nav complete
      })
      .catch(function (error) {
        console.log(error);
      });
  };
}

提前致谢 !

标签: react-nativereduxredux-thunk

解决方案


推荐阅读