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

For example there is an Action:

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

It is possible being in Watcher to get (user: UserInterface) from loginSuccessAction?

Thank You very much for Your answer



Solution 1:[1]

Yes, each of the methods for taking an action will give you the action object, and since you've put the user on the payload property, you can use that. For example with takeEvery:

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

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

Or with take:

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nicholas Tower