What is React?
A page with a button that counts clicks needs to keep the number in sync with every click. In plain JavaScript, you grab that button's text node, add a click listener, and update the number by hand each time someone clicks. Add a search filter, a shopping cart total, and a modal that opens and closes, and there's a whole set of manual updates scattered through the code now, each one a place a bug can creep in when the data changes somewhere else on the page.
React is a JavaScript library for building user interfaces out of components, and it takes that manual bookkeeping away from you. This chapter looks at what that means in practice: the core idea behind React, where it runs, and how it fits into the library-versus-framework question that comes up early for most people learning it.
Components and the core idea
Here's that same click counter written as a React component:
import { useState } from 'react'
function Counter() {
const [count, setCount] = useState(0)
return (
<button onClick={() => setCount(count + 1)}>
Clicked {count} times
</button>
)
}This example uses a few pieces you haven't met yet: the markup inside return is JSX, useState is a hook, and onClick is an event handler. The Components and JSX chapters cover that markup, State covers useState in full, and Events covers onClick, so take the syntax on trust for now and follow the shape of the idea instead.
count is the state. The JSX returned by Counter describes what the button should show for that state. Clicking the button calls setCount, which updates count, and React re-renders the button to match. You never touch the button's text directly. You describe it again for the new value, and React works out what changed on the page.
That's the core idea sitting under every React component: you describe the UI as a function of your data, usually called state, and React takes care of updating the DOM to match. A component is a function that returns a piece of UI, and an app is a tree of components combined together, all working the same way the counter above does.
Where React runs
React runs primarily in the browser, rendering components to the DOM. That's the environment this handbook stays in throughout.
React's component model isn't tied to the DOM specifically, though. Other renderers plug the same model into different targets. The best-known example is React Native, which uses React's components and state model to drive native mobile interfaces instead of a web page. It's mentioned here so the name isn't a surprise later. Teaching it is outside the scope of this handbook.
Library or framework?
React renders UI. It doesn't ship routing, doesn't decide how you load data, and doesn't handle server rendering. Those are choices you make yourself, often by reaching for another tool alongside it. That's the practical reason React counts as a library rather than a full framework: it does one job well and leaves the rest to you, rather than owning the whole app the way a framework does.
The kinds of frameworks covers this distinction in full, including where React sits next to something like Next.js, which does add the missing pieces.
Next up: History and versions, which covers how React got here and what changed release to release.

