Explain how React describes interactive UI
React in one minute
React is a JavaScript library for building user interfaces: the parts of an application people see and use, such as labels, buttons and lists. A component is a reusable description of part of that interface. React uses component descriptions and current data to work out what the interface should display.
A first component
A function is a named piece of JavaScript. In this example, ShopHeading is a component function. The text inside the angle-bracket tags describes a heading. This markup-like notation is called JSX. You will learn its syntax in a later chapter.
export default function ShopHeading() { return <h2>Fresh Market</h2>;}Expected display: a level-two heading reading “Fresh Market”. The export default syntax makes the component available to another module; it does not mount anything on its own. All React/JSX examples in this chapter are static source previews requiring a configured React application, not executable in ByteMind.
How a web interface fits together
HTML supplies structure, CSS controls presentation, and JavaScript supplies behavior. The browser represents the page as a tree of objects called the DOM (Document Object Model). Plain JavaScript can change those objects directly. React is another way to organize the UI behavior; in a browser, React DOM connects React descriptions to the DOM. React does not replace CSS or the browser.
Describe the result instead of every DOM change
Imagine a shopping list whose item count changes from 2 to 3. A direct DOM approach might find a text node and set its text. In React, you can describe the text as a result of the current count. React can then update the displayed result when that data changes. A component’s state is data it remembers between renders; a render means React calculates the next UI description. The following example previews a state-driven counter. You do not need to memorize the hook syntax yet.
import { useState } from 'react';
export default function Basket() { const [count, setCount] = useState(2); return ( <section> <p>Items: {count}</p> <button type="button" onClick={() => setCount(count + 1)}>Add item</button> </section> );}Initially the paragraph says “Items: 2”. Pressing the Add item button once requests a state update to 3, so the next displayed count is 3. useState provides the remembered value and a setter. Braces insert a JavaScript value into JSX; onClick describes what to do when the button is activated. These details will be taught in Chapters 4, 9 and 10. A real button also supports normal keyboard activation.
Common mistake: React is not the entire application
React can describe a shopping cart, but that alone does not provide payment processing, persistent storage, or server authorization. Those responsibilities require other parts of a system. React also does not guarantee that every state update changes a DOM node: an updated description can result in the same visible output.
Practice and next step
On paper, predict the initial count and the count after one activation if a basket starts at 5. Explain which value the component remembers. The next lesson focuses on reading a component and predicting its output.