From the course: React: Design Patterns

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

ResourceLoader component

ResourceLoader component - React.js Tutorial

From the course: React: Design Patterns

ResourceLoader component

- [Instructor] All right, so we just took a big step in making our components more reusable and less tightly coupled when we had this UserLoader thing, take another prop, right? This userId prop, which as we just saw, allowed us to load pretty much whatever user we wanted while keeping our component count to only two components, and also keeping both these components fairly straightforward to use and to maintain. So the next step that we're going to take here is, I would say an even more important one, what happens when we want to load some sort of data besides just the regular users or current user that we've been loading so far, right? So what happens when we want to load data from another endpoint or another URL even? Well, that's where another sort of even more generic version we'll say of this UserLoader component is going to come in and we're going to call that one ResourceLoader. You'll see what this looks like shortly. First though, let's create a new file, we're going to call…

Contents