How React's declarative model works: components hold state, React re-renders the tree, and commits only the parts that changed.
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.
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.
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.
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.
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.
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.
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.
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.