In this video, Emmanuel Henri goes over the rules and what to avoid when working with the context.
- [Instructor] One area to avoid when you're … leveraging context and provider and consumers … is to pass a value here, … because if you're passing a straight value, … so if we're doing something like this for example. … Whenever the provider rerenders, … so whenever something changes and, basically, executes … a new rerender of the provider, … if you want to avoid, all of the consumers, … so in this case, this one is a consumer, … but there could be a lot more. … So if I want to pass this context to a lot more components, … then I'm having an issue. … So all these components will rerender whenever … the provider actually renders. … So if you want to avoid something like this, … the best way to prevent this, … so if the provider rerenders, you want to have only … the components that something … has changed into it to rerender. … Then for performance, what you want to do … is something like this, this.state. … So this is the best way to prevent any renders … when they're not needed. … So if you want to rerender the top level here, …
- Creating a context object
- Implementing the code for updating context
- Updating context from a nested component
- What to avoid when working with context
- How the node tree in React applies to context
- Consuming multiple contexts