Intro to React
Introduction to React
Overview
React is a popular JavaScript library for building user interfaces (UIs). Think of it like building with LEGO blocks - you create small, reusable pieces (called components) and combine them to build complex web applications.
This guide covers:
- What React is and why it’s useful
- Core concepts and terminology
- How React makes web development easier
- Basic React architecture
What is React?
Before React, building web applications was like trying to organize a messy room where everything is connected to everything else. When you moved one thing, it could unexpectedly affect something else. React helps solve this by organizing your code into neat, separate containers (components) that are easier to manage.

Components: The Building Blocks
A component is like a reusable blueprint for a part of your website. For example:
// A simple Button component
function Button({ text, onClick }) {
return (
<button onClick={onClick}>
{text}
</button>
);
}
// Using the Button component
function App() {
return (
<div>
<Button text="Click me!" onClick={() => alert('Hello!')} />
<Button text="Sign up" onClick={() => alert('Welcome!')} />
</div>
);
}
To learn more about components, check out the Components guide.
Why Use React?
Let’s look at why React has become so popular by examining its key features:
1. Predictable Data Flow
Imagine a TV remote control. When you press a button (an action), you expect a specific change on the TV screen (the view). React works the same way - data flows in one direction, making it easier to understand and predict what will happen in your app.

2. Component-Based Architecture
Think of components like recipe cards in a cookbook:
- Each recipe (component) is self-contained
- You can reuse recipes in different meals (pages)
- Changing one recipe doesn’t affect the others
// Recipe card example
function RecipeCard({ title, ingredients, instructions }) {
return (
<div className="recipe">
<h2>{title}</h2>
<ul>
{ingredients.map(ingredient => (
<li key={ingredient}>{ingredient}</li>
))}
</ul>
<p>{instructions}</p>
</div>
);
}
3. State Management
State is like the memory of your application. It keeps track of things that can change, like:
- Is the user logged in?
- What items are in the shopping cart?
- Which theme (light/dark) is selected?
import { useState } from 'react';
function Counter() {
// useState creates a piece of state
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}
To learn more about state, check out the React useState Hook guide.
How React Works
When your app’s data changes, React doesn’t rebuild the whole page. The React docs describe every screen update in three steps: trigger, render and commit.
Trigger the initial render, or a state update
|
v
Render React calls your components to work out what to show
|
v
Commit React changes only the DOM nodes that differ from the last render
|
v
Paint the browser updates the screen
- Trigger: A component renders for one of two reasons. Either it’s the app’s initial render (when you call
createRootand thenrender), or the component’s state (or an ancestor’s state) was updated. Calling a statesetfunction queues a re-render. - Render: React calls your components to figure out what should appear on screen. On the initial render it calls the root component. On later renders it calls the component whose state update triggered the render, then any components that component returns, and so on down the tree. Rendering only calculates the result. It doesn’t touch the page yet.
- Commit: React applies the result to the DOM. On the initial render it puts all the DOM nodes it created on screen. On re-renders it applies only the minimal operations needed to make the DOM match the latest render output. React only changes the DOM nodes if there’s a difference between renders.
After the commit, the browser repaints the screen.
What about the “virtual DOM”? Older tutorials and React’s legacy docs describe this process with the term “virtual DOM”: a representation of the UI kept in memory and synced with the real DOM, a process called reconciliation. The current React docs don’t use that term. They describe the same idea as render and commit.
Example of React’s Efficiency
import { useState } from 'react';
function TodoList() {
const [todos, setTodos] = useState([
{ id: 1, text: 'Learn React' },
{ id: 2, text: 'Build something cool' }
]);
// React re-renders the list, but it only changes the DOM
// nodes that differ between renders — here, the new todo's <li>
function addTodo(text) {
setTodos([...todos, { id: crypto.randomUUID(), text }]);
}
return (
<>
<button onClick={() => addTodo('New todo')}>Add todo</button>
<ul>
{todos.map(todo => (
<li key={todo.id}>{todo.text}</li>
))}
</ul>
</>
);
}