Summary
In this chapter, we learned how to create global states with React Context. The Context propagation works to avoid passing props. If you understand the Context behavior correctly, implementing global states with Context is straightforward. Basically, we should create a Context for each state piece to avoid extra re-renders. Some best practices will help in the implementation of a global state with Context, particularly the concrete implementation of createStateContext
, which will help when organizing your app code.
In the next chapter, we will learn another pattern of implementing a global state with subscriptions.