Reactjs 这部传奇被多次传唤

Reactjs 这部传奇被多次传唤,reactjs,redux-saga,Reactjs,Redux Saga,如何避免传奇故事被多次传唤。一旦我发送了一个动作,我就多次收到结果。我不知道我错过了什么 Saga.js export function* watchRegisterUser() { yield takeLatest(REGISTER_USER, registerWithEmailPassword); } export function* watchLoginUser() { const logi = yield takeLatest(LOGIN_USER, loginWithEmai

如何避免传奇故事被多次传唤。一旦我发送了一个动作,我就多次收到结果。我不知道我错过了什么

Saga.js

export function* watchRegisterUser() {
  yield takeLatest(REGISTER_USER, registerWithEmailPassword);
}

export function* watchLoginUser() {
  const logi = yield takeLatest(LOGIN_USER, loginWithEmailPassword);
}

export function* watchLogoutUser() {
  yield takeLatest(LOGOUT_USER, logout);
}

export default function* rootSaga() {
  yield all([
    fork(watchLoginUser),
    fork(watchLogoutUser),
    fork(watchRegisterUser)
  ]);
}
当我输入错误的凭据时,会收到响应并显示通知,第一次工作正常。但是,当我更改凭据时,会收到通知(多次)。即使在国家

参考

我不确定我错过了什么

谢谢

更新

function* loginWithEmailPassword({ payload }) {

  const { history } = payload;
  try {
    const response = yield call(loginWithEmailPasswordAsync, payload.user);
    console.log("login  :", response);
    if (response.status >= 200 && response.status < 300) {
      const loginUser = yield response.json();

        localStorage.setItem("access_token", loginUser.access_token);
        yield put(loginUserSuccess(loginUser));
        history.push("/");

    } else if (response.status === 400) {
      yield put({
        type: LOGIN_USER_FAILURE,
        error: "Email and Password are wrong!"
      });
    }
  } catch (error) {
    yield put({ type: LOGIN_USER_FAILURE, error: "Something went wrong!" });
  }
}
function*loginWithEmailPassword({payload}){
const{history}=有效载荷;
试一试{
const response=yield调用(loginWithEmailPasswordAsync,payload.user);
日志(“登录:”,响应);
如果(response.status>=200&&response.status<300){
const loginUser=yield response.json();
setItem(“access\u token”,loginUser.access\u token);
收益率卖出(loginUserSuccess(loginUser));
历史。推送(“/”);
}else if(response.status==400){
收益率看跌期权({
类型:登录\用户\失败,
错误:“电子邮件和密码错误!”
});
}
}捕获(错误){
yieldput({type:LOGIN\u USER\u FAILURE,error:“出错!”});
}
}

您能在发布触发传奇的动作的地方分享代码吗?@azundo谢谢。我已经更新了代码。看一看。@Gigabyte您找到问题的解决方案了吗?