React
You might say
People keep saying to use React for websites. What's better about it than writing the page directly?
A JavaScript library for building interactive interfaces from components and stateAfter an item is added to a cart, React can update the count from 2 to 3. Whether the item was actually saved and remains after a refresh still depends on backend and data storage.
Know first
React.js
Why does only this part update after a click?
Counter.jsx
1
const [count, setCount] = useState(0)2
<button onClick={() => setCount(count + 1)}>3
Added {count} item(s)4
</button>Canvas tote¥ 79
count in state is now 0
The button reads count. When count changes, React updates this button text with the new value.
How a state change updates a component
A component is one interface piece:A button and a nearby task list can be separate pieces.
State holds the current value:A click changes a counter from 0 to 1; state is what this part should show now.
React recalculates the view:React recalculates the related component and the renderer updates the needed DOM.
Learn next
Further reading