Skip to content
tezvyn:

Thinking in React: Decomposing UIs into Components

Source: react.devMediumHow cards are made

Thinking in React: Decomposing UIs into Components

Think of UIs not as one big page, but as a tree of reusable components. Start by breaking a design mockup into a hierarchy of pieces. The footgun is creating 'god components' that do too much; each component should have a single responsibility.

Why it exists

Modern user interfaces are complex. Building them as single, monolithic blocks of code makes them difficult to debug, maintain, and reuse. The "Thinking in React" process provides a structured, component-based approach to manage this complexity and build scalable applications.

The mental model

Instead of a static page, see your UI as a tree of independent, reusable components. Just as you'd break a large program into smaller functions or objects, you decompose a UI design into self-contained pieces. Each component encapsulates its own markup, logic, and sometimes state, making the overall system easier to reason about.

How it works

The process starts with a design mockup. First, you break the UI into a component hierarchy by drawing boxes around every logical piece and giving it a name. A good guideline is the single responsibility principle: a component should ideally do only one thing. If it grows too complex, it should be decomposed into smaller subcomponents. Next, you arrange these components into a parent-child hierarchy that reflects their nesting in the UI. This structure often naturally maps to the shape of your data model. Finally, you build a static version of the UI by creating these components and passing data down from parent to child.

When to use it

This component-first mindset is the standard and most effective way to build any application in React. It's the core workflow for translating a design into a functioning app, whether you're building a single interactive widget or a large-scale, data-heavy dashboard. The more complex and interactive the UI, the more beneficial this approach becomes.

When not to use it

The component model can be overkill for simple, static websites with little to no interactivity. If your goal is to display content that doesn't change and doesn't require user input or state management, using plain HTML and CSS is often a simpler and more performant solution. The overhead of the React library is not justified in these cases.

One canonical example

Building a searchable product table. The entire UI might be a single FilterableProductTable component. This parent component would contain a SearchBar and a ProductTable. The ProductTable would then render multiple ProductRow components and group them under ProductCategoryRow components. This breaks one screen into five distinct, nested components, each with a clear purpose.

Interview question

When decomposing a UI into React components, what is the most crucial principle to follow for effective design?

  • a.Structuring components to directly mirror the backend API's data model.
  • b.Ensuring each component manages its own distinct piece of application state.
  • c.Grouping elements that share similar styling or visual characteristics.
  • d.Adhering to the single responsibility principle, where each component does one thing.Correct
Why?

The card emphasizes that "a good guideline is the single responsibility principle: a component should ideally do only one thing" to avoid "god components." While other options might be considerations, they are not the primary principle for decomposition itself.

Just read this? Test yourself on what you have been reading.

Read the original → react.dev

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on react — each one lists the topics its interview covers.

See open roles