February 2019
Intermediate to advanced
204 pages
4h 52m
English
We've already discussed what a reducer is and what it does. In this section, we are simply going to set up a reducer for login. Create a reducer.js file inside app/containers/App. Since we are dealing with immutable JS, as discussed in Chapter 2, Testing:
import { fromJS } from 'immutable';import Cookie from 'js-cookie';import { LOGIN_REQUEST, LOGIN_SUCCESS, LOGIN_FAILURE, LOGOUT_REQUEST,} from 'containers/Login/constants';// The initial state of the Appconst initialState = fromJS({ loading: false, currentUser: {},});function appReducer(state = initialState, action) { switch (action.type) { case LOGIN_FAILURE: case LOGIN_REQUEST: case LOGOUT_REQUEST: { Cookie.remove('token'); return state.set('loading', true).set('currentUser', ...Read now
Unlock full access