Skip to content

Latest commit

 

History

History
23 lines (15 loc) · 1.21 KB

File metadata and controls

23 lines (15 loc) · 1.21 KB

Reading notes for class 32 of 401

Context API - Behaviors

When you have multiple contexts, what component type should you use (class/function) and why?

The particular component type doesn't matter in cases with multiple contexts, however I would use a functional component.

What are some good use cases for using the Context API for global state?

Context is primarily used when some data needs to be accessible by many components at different nesting levels.

How can you best test context?

Make tests unaware of its existence and avoiding mocks.

Vocab

context

  • React Context is a method to pass props from parent to child component(s), by storing the props in a store(similar in Redux) and using these props from the store by child component(s) without actually passing them manually at each level of the component tree.

useContext()

  • A hook used to create common data that can be accessed throughout the component hierarchy without passing the props down manually to each level. Context defined will be available to all the child components without involving “props”.

static context

  • A static method or, block belongs to the class and these will be loaded into the memory along with the class.