From the course: React: Design Patterns

Unlock this course with a free trial

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

CurrentUserLoader component

CurrentUserLoader component - React.js Tutorial

From the course: React: Design Patterns

CurrentUserLoader component

- [Narrator] All right, so now that we've seen the basics of loading data from a server and, you know, displaying that in a component, and we've seen what could be a slightly better way, right? This way is very similar to what we saw with the layout components, where it allows us to really separate the way that data's being rendered from the way that it's being loaded. Okay, so what we're going to want to do here is, first of all instead of calling this "CurrentUserInfo," we'll call this something like "CurrentUserLoader." All right, so "CurrentUser" and "CurrentUserLoader." And what we want to be able to do, as I said previously, is automatically have this UserInfo component get access to the data loaded by this component that's surrounding it. All right? So here's what this is going to look like, and by the way, this is also a common pattern that you'll see sometimes used with libraries like React Router, right, so it does have a pretty wide-ranging application beyond just loading…

Contents