React · Lesson 2 of 120
How React Works
Describe it, React updates it.
Without React, you change the page step by step. Find this element, change its text, add that class. With React, you describe what the page should look like for the current data. React works out the changes for you.
- Step by step
- Or describe it
- React updates the page
Two ways to build a page
Plain JavaScript gives instructions, one change at a time, and it's easy to forget one. React describes the result. When the data changes, you describe it again, and React updates only what's different.
Plain JavaScript
- Find the elementChange its textEasy to miss one
React
- Describe the UIFrom the dataReact updates it
The React loop
You have some data, called state. A component turns it into a description of the UI. React shows it on the page. The user clicks, and the state changes. Then the loop starts again.
- State
- Component
- Page
- User acts
- New state
Summary
You describe the UI from data, and React keeps the page in sync. Next, your first component.
Key takeaways- Describe, don't instruct
- State to UI
- React updates
Next up: Your First Component — a function that returns UI