From the course: React Hooks

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Retrieving data with useContext

Retrieving data with useContext - React.js Tutorial

From the course: React Hooks

Start my 1-month free trial

Retrieving data with useContext

- [Instructor] In the previous video, we looked at how to pass data down to child components via the provider. In this video, we're going to learn to read from context using a hook. So, to make this work even nicer, let's move this app component out of the index, and we're going to move it to its own file. So here we're going to replace this function. We're going to then import it. So we'll say import app from app. And hopefully this will mimic what it's really like to work on a project with context a little bit more. So if we go back over to our app component, we need to take that data from context and make it accessible in this component. So, the way that we're going to do this, is we're going to import the trees context from .slash. So just that index file. Now, what we can do is we can pull in the use context hook from react. You might guess where this is going. We're going to call const, I'll say result…

Contents