# React Declarative UI Anatomy

How React's declarative model works: components hold state, React re\-renders the tree, and commits only the parts that changed\.

By Numa

Topic: Computing, AI &amp; Electronics

[Open the interactive Jig](https://ask.jig.com/j/s4QnuCfutGsd)

## Transcript

### 1. A screen made of building blocks

App screens are built from reusable pieces called components, like LEGO bricks\. The board shows the component tree: App holds Header, Counter and List\. The monitor shows the screen they build\.

React began at Facebook in 2011 and was shared with everyone in May 2013\.

### 2. The old way: step by step

Older code changed the page piece by piece: find the number, change it, then find the badge and change it too\. This is called imperative\. Press the button: this code forgets the badge\.

The badge turns red: the screen disagrees with itself\.

### 3. Describe it, don't command it

React is declarative: you describe the screen for each state, and React works out the changes\. State is data a component remembers\. The count lives in App's chip, so both numbers follow it\.

Like telling a taxi where to go instead of every turn\.

### 4. Trigger, then render

Changing state triggers an update \(lamp 1\)\. Then React renders \(lamp 2\): it asks each component what it should look like now\. The blue glow runs down the whole tree under App\.

Render means asking components, not drawing pixels\.

### 5. Commit only what changed

React compares the new answer with the last one, then commits \(lamp 3\): it touches only what differs, and the browser paints it\. Eight components rendered, yet only two numbers flash\.

Same result as last time? React leaves the page alone\.

### 6. State lives where it is used

Each fruit's tick is its own Item's state\. Tap a fruit row or its Item block: only that Item renders, and only its box changes\.

State held low in the tree stays local\.

### 7. Keys keep track of who is who

Each Item has a key, a name tag React uses to recognise it\. Shuffle: React moves the existing rows instead of rebuilding them, so each tick stays with its fruit\.

You can also tap the List block to shuffle\.

### 8. Why it changed interface design

Describing screens from state keeps the screen in step with the data, which made big apps easier to build\. The idea spread to React Native, SwiftUI and Jetpack Compose\. Play: tap App or \+, fruit rows, or List\.

W3Techs finds React on about 6 percent of all websites\.
