Courses / React 19: From Components to Production / Chapter 3
Module 2 · React Foundations · Chapter 3 of 30
Introduction to React: Elements, JSX and the First Render
Builds on JavaScript for React: Values, Closures, Arrays, Async and the DOM. Next up: Components: Props, Children, Conditions, Lists and Keys.
Part 1 · Declarative UI: describe the screen, not the edits
Two ways to keep a page right
A village library puts a board at the door listing its new arrivals, and the list changes every week. Keeping such a list on screen in step with the data behind it is the problem React solves.
The first answer is imperative: you give the browser each step. Create an element, put text in it, append it, then find the counter and change its text. The second is declarative: you write a function that, given the current data, returns the screen that should exist, and a library works out the steps. React is the declarative answer.
In React terms, the data that can change over time is state, and the description of the screen is built from it. When the state changes, you describe the screen again for the new state. React compares the new description with the old one and edits only what differs. You stop writing "how to get from the old screen to the new one".
What React keeps for you
The imperative style makes you track two things that must agree: the data and the page. Every place that changes the data must also change the page, and each page element that shows a value must be found and updated. A bug appears whenever one path forgets.