reading-notes

Context API

Choosing the State Structure

  1. Summarize the five principles for structuring state.

The five principles for structuring state are as follows:

Passing State Deeply with Context

  1. What problem do Contexts aim to solve?

Contexts aim to solve the problem of prop drilling, which occurs when you need to pass data through multiple levels of nested components. Contexts provide a way to share data between components without explicitly passing it through each intermediate component in the component tree.

  1. What is one technique to try before useContext?

Before using the useContext hook, one technique to try is prop drilling. Prop drilling involves passing data down through the component tree as props, even if some intermediate components don’t directly use the data. While prop drilling can be a bit cumbersome, it can work well for smaller applications or when the data needs to be accessed by only a few components.

  1. What hook complements useContext for complex applications?

The useReducer hook complements useContext for complex applications. While useContext provides a way to access context values, useReducer is a hook that helps manage complex state logic by providing a dispatch function and a state object. It is especially useful when the state updates involve multiple actions and complex state transitions.

Bookmark and Review

Keep these pages handy - they answer questions that show up regularly for this lab.

Back