reading-notes

Class 401.15

Notes

Readings

Choosing the State Structure

  1. Summarize the five principles for structuring state.

    The five principles are: 1) only include minimal representation of the state, 2) compute everything else on demand, 3) let components own their state, 4) keep state as normalized as possible, and 5) don’t put derived state in the state. For example, instead of storing an array length, calculate it each time from the array itself.

Passing State Deeply with Context

  1. What problem do Contexts aim to solve?

    Contexts aim to solve the problem of “prop drilling” where you have to pass data through many layers of components. For example, if you have a theme that needs to reach many components, you can use context instead of passing the theme down each level.

  2. What is one technique to try before useContext?

    One technique to try before using useContext is component composition. This involves passing components as props or using children props. For example, instead of passing data, you may pass a <Header /> component with its own props

  3. What hook complements useContext for complex applications?

    The useReducer hook complements useContext for complex applications. When state logic is complex, useReducer can manage it in a more predictable way than useState. For example, if you have a shopping cart with many possible actions (adding, removing items, etc), useReducer is a good choice.

Things I want to learn more about

References