From the course: Building Modern Projects with React
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
Refactoring the to-dos reducer - React.js Tutorial
From the course: Building Modern Projects with React
Refactoring the to-dos reducer
- [Josh Olenslager] Alright, so now that we're loading our to-dos from the server, the next thing that we're going to want to do is actually modify our to-dos slice so that it takes that into account. Now what we're going to need to do here is have our to-dos slice, listen for that same event, right? This same loading completed event that we're defining in our loading slice. And when it gets that, it's going to need to take the to-dos that were loaded and actually set those as the value for our to-dos state. So, here's what this is going to look like. All right? So, here's what we're going to have to do here. First of all, you might be wondering if we can just add another reducer called something like loadingCompleted to our to-DO slice. Well unfortunately while that would allow us to add another action and another reducer to our to-do slice, that wouldn't actually be the same event as what we had over here. The same action rather, right? So, if we define loading completed inside our…
Contents
-
-
-
-
-
-
-
-
-
-
(Locked)
Why do we need Redux-Thunk?1m 49s
-
(Locked)
How does Redux-Thunk work?1m 47s
-
(Locked)
The Todos API4m 6s
-
(Locked)
Keeping track of the loading state4m 8s
-
(Locked)
Loading data with Thunks10m 35s
-
(Locked)
Refactoring the to-dos reducer6m 25s
-
(Locked)
Using Thunks to create server resources7m 56s
-
(Locked)
Using Thunks to delete server resources5m 30s
-
(Locked)
Challenge: Using Thunks to update server resources38s
-
(Locked)
Solution: Using Thunks to update server resources3m 47s
-
(Locked)
-
-
-
-