reading-notes

Reading: Context API

Choosing the State Structure

When structuring state, it’s essential to adhere to certain principles to ensure scalability, maintainability, and performance. Here are the five principles for structuring state:

  1. Single source of truth: Keep all state in a centralized location to avoid inconsistencies.
  2. State is read-only: State should be immutable to prevent unexpected mutations.
  3. Changes are made with pure functions: Use pure functions (reducers) to update state in a predictable manner.
  4. Isolate state changes: Group related state together to simplify updates and reduce side effects.
  5. Normalize nested/relational data: Flatten nested structures and store relational data separately to improve performance and simplify data access.

Passing State Deeply with Context

Contexts in React aim to solve the problem of prop drilling, where props need to be passed through multiple layers of components. Here’s a summary:

Bookmark and Review

Keep these resources handy for reference:

Things I Want to Know More About