React is the most widely-used library for building user interfaces — this very site is built with it. Its core idea is simple: describe your UI as a tree of small, reusable components, and let React keep the screen in sync with your data. This chapter assumes you're comfortable with the JavaScript course; if arrays, objects and arrow functions feel shaky, review those first.
Why React?
Without a library, keeping the DOM in sync with changing data means hand-writing dozens of querySelector updates that quickly tangle. React flips it around: you write what the UI should look like for the current data, and React figures out the minimal DOM changes to get there. You describe the destination; React handles the journey.
Setting up a project
The fastest modern start is Vite. It scaffolds a project with a dev server, hot reloading and a build step in one command:
npm create vite@latest my-app -- --template reactcd my-appnpm installnpm run dev
Components
A component is just a JavaScript function that returns markup. The name must start with a capital letter — that's how React tells your components apart from plain HTML tags:
function Welcome() {return <h1>Hello, Albero!</h1>;}export default Welcome;
Components compose — you build big UIs by nesting small components, each responsible for one piece:
function Header() {return <header><h1>Albero Academy</h1></header>;}function App() {return (<div><Header /><Welcome /></div>);}
JSX rules
That HTML-in-JavaScript is JSX. It looks like HTML but is really JavaScript, so it has a few rules:
- Return one root element. Wrap siblings in a parent or an empty
<>…</>fragment. classbecomesclassName(class is a reserved JS word), and attributes are camelCase (onClick,htmlFor).- Embed any JavaScript expression in
{ }— a variable, a calculation, a function call. - Every tag must close, including empty ones:
<img />,<br />.
function Greeting() {const name = "Aanya";const hour = new Date().getHours();return (<div className="greeting"><h2>Hello, {name}!</h2><p>{hour < 12 ? "Good morning" : "Good afternoon"}</p><p>2 + 2 = {2 + 2}</p></div>);}
Practice
Scaffold a Vite React app. Build a ProfileCard component that renders your name, role and a short bio, and render three of them inside an App component.
Key takeaways
- 01React keeps the DOM in sync with your data — you describe the UI, React updates the screen.
- 02Vite is the fastest way to start: npm create vite@latest.
- 03A component is a function (capitalised name) that returns JSX; compose big UIs from small components.
- 04JSX rules: one root element, className not class, camelCase attributes, {expressions}, self-close every tag.
- 05Keep components small and single-purpose so they stay reusable.
