Check out a free preview of the full Complete Intro to React v4 course:
The "Context Wrap Up & Questions" Lesson is part of the full, Complete Intro to React v4 course featured in this preview video. Here's what you'd learn in this lesson:

Brian wraps up context by saying it's one of the most difficult things to understand in core React. He also discusses when it makes sense to use context or not.

Get Unlimited Access Now

Transcript from the "Context Wrap Up & Questions" Lesson

[00:00:00]
>> Brian Holt: So that was context. I would say that's the most difficult thing about core React, is understanding context, it's the more advanced features. There's other cool patterns you can do with React, like render props and stuff like that, which I'm not talking about today. Kent has a course on it here on Frontend Masters, which is great.

[00:00:19] So check that out if you want to get into more advanced patterns with React.
>> Brian Holt: But I think context is a more difficult one to wrap around, cuz it's just a little bit more abstract. It's a little bit more handwavy and black magic-y, so.
>> Speaker 2: How do you go about making a decision to either stay with the more simple pattern of parents passing props down into children or move that data into something like context?

[00:00:49] What does it look like when you're agonizing over that moment?
>> Brian Holt: I wait until I absolutely can't stand it anymore. Because again, I think if you have the very explicit pattern of passing props down from parent to children, it makes your code easier to come back to later and say like, I understand how this gets from here to here to here to here.

[00:01:09] I like to use the example of you have a logged in user and this logged in user has some data associated with it, right? That's gonna be used everywhere in your application, right? So if I start having to moving things up into the root parent component and passing it into every route, then I'll start questioning it, like, maybe I should use context for this.

[00:01:32]
>> Brian Holt: And I guess that's what it is. If something has to live in the parent component and is used in more than two places, in two places I'll probably suffer and just deal with it that way. But if I'm using in three or four places, I might move that into context.

[00:01:48]
>> Brian Holt: But I'm trying not to be too prescriptive with my attitudes about this. I want you to learn these patterns, yourselves, and make your own decisions, right? According to your own sensibility, according to what works for your team. I'm showing you one opinion of how this works. But I'm hoping that you understand the patterns and grasp the patterns so that you yourself can make these decisions.