AI Hints
Home›React Tutorial›Thinking in React
React · Lesson 34 of 120

Thinking in React

From design to components.

⏱ 2 min read▶ Video at 26:28🎓 Free
Watch this lesson in the React courseWatch on YouTube ↗Full React course

Given a design, how do you turn it into React? There's a simple process. Break the page into components, build a static version, then add just the state you need.

  • Start from a design
  • Break it up
  • Add state last

Five steps

First, draw boxes around each part of the design, and name them. Second, build a static version with props only. Third, find the minimal state. Fourth, decide where that state lives. Fifth, pass functions down, so children can change it.

  1. Draw boxes
  2. Static version
  3. Minimal state
  4. Where it lives
  5. Functions down

A shop page

Our shop page becomes a tree of components. The app holds a search bar and a product table. The table holds a row for each product.

App
ProductTable
ProductRow

Minimal state

Ask three questions about each piece of data. Does it change over time? Is it passed in from a parent? Can you calculate it from other data? Only data that changes, and can't be passed or calculated, is state.

keyvalue
Changes?maybe state
Passed in?a prop
Calculated?not state
Elsestate

Summary

Break the design into components, build it static, then add the minimal state. Next, where state lives.

Key takeaways
  • Boxes
  • Static first
  • Minimal state
Next up: Where State Lives — the closest common parent