Module 37: State Management

Lesson 5 of 5 · 15–25 minutes

Choosing an approach

🏠The everyday picture

You don't hire a removals lorry to carry one chair across the room, and you don't move house with a shopping bag. Choose the tool for the size of the job.

📘What it really is

A simple decision path for each piece of state:

  1. Can it be calculated from other state or props? Then it isn't state; calculate it while rendering.
  2. Should it be in the URL (page, filters, search, selected tab worth sharing)? Use the router.
  3. Does it come from a server? Use a data-fetching tool.
  4. Is it used by one component? useState there.
  5. Used by a few nearby components? Lift it to their common parent.
  6. Used across the app (user, theme)? Context, with a reducer if changes are complex.
  7. A large app with lots of shared, fast-changing client state? Consider a store like Zustand or Redux Toolkit.

  8. Most apps need only steps 1 to 6.

  9. With AI: AI sometimes adds Redux or a big store to a small app. Ask what problem it solves that the steps above don't.

🖱️Try it

Apply the decision path to every item in your Lesson 1 list and update the app to match. Remove any state that can be calculated. Write the final decisions in your README under "State".

✅Quick check

fullName is stored in state alongside firstName and lastName. What does the path say?

Show the answer

It can be calculated, so it shouldn't be state.

An AI adds Redux to a three-page app with one shared value. What do you ask?

Show the answer

What problem it solves that Context or lifting state wouldn't; probably none, so keep it simpler.

← PreviousServer state is different
ProLearners Assist