From the course: Building Modern Projects with React

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Creating reducers

Creating reducers

From the course: Building Modern Projects with React

Start my 1-month free trial

Creating reducers

- [Instructor] Now that we've defined our actions for creating and removing todos, let's see how to define a reducer that will keep track of the state of the todos in our application as well as behave appropriately when our components trigger one of these actions that we just defined. First let's create a new files in our todos directory called reducers.js and this, as you may have guessed, is where we'll put our reducer code. So let's talk about what a reducer should look like and how it works exactly. Well, at its core, a reducer is just a function named after whatever resource in the Redux store it's in charge of managing. So for this reducer we're going to define it by saying export const and we're going to call this reducer todos. And reducers take two arguments. The first one, we'll call state, and the second one we'll call action. And it's going to be a function. So here's how reducers work. Every…

Contents