August 2017
Beginner
374 pages
10h 41m
English
We start with implementing the postsReducer function. First, we have to think about the function definition. This includes the initial/default state. In this case, we want to handle an array of posts, so the initial state is an empty array []. The second argument is the action. The full function definition looks as follows:
function postsReducer (state = [], action) {
We set the initial state through a default value. If the state is undefined (which it is, when the Redux store gets initialized), the state will be set to the default value (in this case, []). We will put our reducers into a separate file:
import { CREATE_POST, EDIT_POST, ...Read now
Unlock full access