switch·Esc back

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
1const [count, setCount] = useState(0)
2<button onClick={() => setCount(count + 1)}>
3 Added {count} item(s)
4</button>
localhost:3000
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 pieceA button and a nearby task list can be separate pieces.

State holds the current valueA click changes a counter from 0 to 1; state is what this part should show now.

React recalculates the viewReact recalculates the related component and the renderer updates the needed DOM.

Learn next
Further reading