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
- [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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Why do you need Redux?4m 11s
-
How does Redux work?4m 35s
-
Adding Redux to a React app3m 24s
-
Creating Redux actions4m 16s
-
Creating reducers6m 23s
-
Connecting components to the store7m 1s
-
Running a React-Redux application4m 32s
-
Persisting the Redux store6m 43s
-
Redux DevTools3m 34s
-
Redux best practices3m 53s
-
Challenge: Adding a Redux flow1m 56s
-
Solution: Adding a Redux flow4m 14s
-
-
-
-
-
-