Instructor: React 16.6 introduced the ability for class components to access context directly without having to use a consumer and the render props pattern. To do this, at the top of the class, we can declare a static property called contextType and set it equal to the full user context.
It needs to be the full context and not just the consumer. Right now, user context is only exporting provider and consumer. We'll go into that file. At the top, we'll create a variable called user context and save the context into there as well as destructuring provider and consumer.
Then at the bottom, we can export this user context. Back in user menu, we can import the user context which we're already using. Down in the render function, we don't need to use the consumer anymore, because we can access these values directly.
This.context is the value that was given to the provider, so we can destructure this directly into user and logout. Now, we can delete the consumer, and we've reduced the nesting by two levels and the app is still working.
For a component that uses two contexts, like message list here with user consumer and email consumer, it's important to know that this contextType property is only available on classes.
For a component like message list, we would have to convert this to a class before we could set the contextType and contextType only works for a single context. If it's using two contexts like this, we'd only be able to save one of them into contextType.