Redux 传奇。守望者。如何从动作中获取数据?

Redux-Saga. Watcher. How can I get data from an action?

例如有一个动作:

export const loginSuccessAction = (user: UserInterface) => {
  return (dispatch: Dispatch<ActionInterface>) => {
    dispatch({ type: ActionTypes.LOGIN_SUCCESS, payload: user });
  };
};

是否可以在 Watcher 中从 loginSuccessAction 获取(用户:UserInterface)?

非常感谢您的回答

是的,每个用于执行操作的方法都会为您提供操作对象,并且由于您已将用户放在负载 属性 上,您可以使用它。例如 takeEvery:

function* watchLogin() {
   yield takeEvery(ActionTypes.LOGIN_SUCCESS, loginSuccessSaga);
}

function* loginSuccessSaga(action) {
  console.log('user: ', action.payload);
}

take:

function* someSaga() {
  const action = yield take(ActionTypes.LOGIN_SUCCESS);
  console.log('user: ', action.payload);
}