September 2018
Beginner
156 pages
3h 28m
English
A Reducer in Redux alters the state of an entity based on the action dispatched to the store. A Reducer is a pure function that accepts two parameters: state and action. The Reducer then returns an updated state based on the value store in action.type. For example, consider the following reducer:
const todoReducer = (state = [], action) => { switch (action.type) { case 'ADD_TODO': return [ ...state, { id: action.payload.id, text: action.payload.text, isCompleted: action.payload.isCompleted } ]; default: return state; }}
The initial state of todoReducer is set to an empty array (state parameter's default value) and a TODO is added to the list when the action type is ADD_TODO. One of the core tenets of Redux is not to mutate the state ...
Read now
Unlock full access