February 2019
Intermediate to advanced
204 pages
4h 52m
English
When a user enters their login credentials and hits the submit button, we are already dispatching the correct action. Now we are going to listen to that action using Saga. To do so, we create our first Saga inside app/Login/saga.js:
import request from 'utils/request';import { notification } from 'antd';import { call, put, takeLatest } from 'redux-saga/effects';import { LOGIN_REQUEST } from './constants';import { onLoginSuccess, onLoginFailure } from './actions';export function* onLoginRequest(action) { try { const { success, user, message } = yield call(request, 'api/users/signin', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(action), }); if (!success) { throw message; } yield put(onLoginSuccess(user)); ...