如何解决错误“操作必须是普通对象。在Redux-Saga中使用自定义中间件进行异步操作

我正在使用redux saga实现登录,该登录saga可以正常工作,直到我发布以下错误信息:“操作必须是普通对象。对异步操作使用自定义中间件。

为什么会出现此错误?,一切正常。

我的传奇故事如下:

function* loginWithEmailSaga(payload) {
  const headerParams = {
    'Content-Type': 'application/json'
  };
  const apiCall = () => axios.post(route,{
    username: payload.email,password: payload.password
  },{ headerParams },).then(response => response.data)
    .catch(err => {
      console.log(err);
    });

  try {
    const data = yield call(apiCall);

    console.log(data);
    if (data.success) {
    yield put(loginWithEmailSuccess(data.data));
    yield history.push('/app');

    }
  } catch (error) {
    console.log(error);
    yield put(loginWithEmailFailure(error));
  }
}

我的动作是这样的

export const loginWithEmail = (email,password) => ({
  type: types.LOGIN_WITH_EMAIL_REQUEST,email,password
});

export const loginWithEmailSuccess = credential => ({
  type: types.LOGIN_WITH_EMAIL_SUCCESS,credential:credential.data
});

export const loginWithEmailFailure = error => ({
  type: types.LOGIN_WITH_EMAIL_FAILURE,error
});

redux的历史如下:

history of redux

huangyi_liyanping 回答:如何解决错误“操作必须是普通对象。在Redux-Saga中使用自定义中间件进行异步操作

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3162476.html

大家都在问