LLearnCode
Academy/react/The React mental model

beginner · 20 minute study

Compose small contracts into useful interfaces

Composition prevents giant condition-heavy components and makes accessible behavior reusable.

Loading progressEvidence grows with practice
Useful preparation · 1 prerequisite

Use this as a map, not a lock. If these ideas are familiar, continue.

First, build a mental model

A component is a function with a UI contract. Props are its inputs; children let a caller choose content while the component owns a useful structural responsibility.

  1. Pass data down through props; do not mutate props.
  2. Use children to reuse layout without hard-coding every content variant.
  3. An event prop reports intent to the parent.
  4. Choose a component boundary around responsibility, not every few lines of markup.
Read the codejsx · educational example
function Panel({ title, children }) {
  return <section aria-label={title}><h2>{title}</h2>{children}</section>;
}
function ItemRow({ item, onChoose }) {
  return <button onClick={() => onChoose(item.id)}>{item.name}</button>;
}
// <Panel title='Inventory'><ItemRow item={item} onChoose={selectItem} /></Panel>
  1. Parent

    The parent supplies data and decides what selecting an item means.

  2. Row

    The row renders the current item and reports a selection event.

  3. Panel

    The panel owns its semantic wrapper while accepting arbitrary content.

Production thinking

Take this beyond the example.

Preserve semantics and labels in reusable controls. A design-system wrapper should not hide keyboard behavior or require a caller to guess its state ownership.

Sources and further reading

Your evidence

unseen is a local learning signal, not a credential or proof of production competence.

Explain the mental model, then explicitly acknowledge it. Opening a page is not evidence.

Supported retries can complete this lesson. Independent evidence and delayed review determine the skill stage.

Next lesson · Choose one owner for each fact →