Creating Saga

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)); ...

Get Redux Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.