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

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