Skip to Main Content
Redux Quick Start Guide
book

Redux Quick Start Guide

by James Lee, Tao Wei, Suresh Kumar Mukhiya
February 2019
Intermediate to advanced content levelIntermediate to advanced
204 pages
4h 52m
English
Packt Publishing
Content preview from Redux Quick Start Guide

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)); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Redux Made Easy with Rematch

Redux Made Easy with Rematch

Sergio Moreno
Learning Redux

Learning Redux

Daniel Bugl
The React Workshop

The React Workshop

Brandon Richey, Ryan Yu, Endre Vegh, Theofanis Despoudis, Anton Punith, Florian Sloot, Daniel Bugl, Brandan Jones, SudarshanReddy Kurri, David Parker, Cihan Yakar

Publisher Resources

ISBN: 9781789610086Supplemental Content