liveBook · Manning

Component hierarchy

As explained in React Quickly, Second Edition

A component hierarchy is a tree-structured organization of components connected through parent–child containment, rendering, or delegation relationships.

A component hierarchy organizes a React interface as a tree of parent and child components. Parents compose children, pass properties downward, and divide responsibility across the interface. The hierarchy turns a desired HTML result into an implementable JSX structure. section 11.1.2 section 11.7

Design a hierarchy by working from the visible interface toward increasingly complete behavior:

  • Start with the desired HTML output, then choose components that can render equivalent JSX. section 11.2.1
  • Balance complexity and responsibility instead of creating either one component for everything or one component for every HTML node. section 11.1.2
  • Begin with a static, stateless structure and add state, lists, and other complexity gradually. section 11.7
  • Pass data through intermediate components when necessary, while recognizing that unused forwarding can make a hierarchy verbose. section 10.1

Dashboard and menu hierarchies

A dashboard can place Header and Main beneath Dashboard, then render UserButton and Welcome deeper in the tree. If the user name originates at Dashboard, it may pass through Header and Main even though those components only forward it. A website menu uses App, Menu, and MenuItem; passing an array of links lets Menu render a dynamic number of MenuItem instances. section 10.1 section 11.3.3

Figure 11.11 We now pass a property to the Menu component from App, and we then use that property to generate a dynamic number of MenuItem instances.
11-11

Use the hierarchy diagram to follow data from App to Menu and from Menu to its dynamically generated MenuItem instances. section 11.3.3

How React Quickly, Second Edition covers it

How deep it goes
Explains boundary choices, nesting, prop flow, and incremental growth, but does not prescribe one universally correct structure.
Examples
Uses dashboards, website menus, timers, and multicomponent to-do applications as hierarchy examples.
What it assumes
Assumes the ability to describe desired HTML output and introduces component decomposition and prop flow through practical interfaces.
What you can do after
Build React interfaces by deriving component trees from desired output and extending them with props, state, and dynamic lists.
How it connects
Connects component trees with JSX, props, state, lists, and context.

Also explained in

Compare how 2 books explain component hierarchy →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React Quickly, Second Edition. The section links point to the parts of the book it draws on.