What React is and how it works
React is a JavaScript library for building user interfaces from components. You describe what the interface looks like for the current data, and React updates the page when the data changes.
React is useful wherever the interface changes in response to user actions and new data: forms, lists, filters, user accounts, single-page applications. React itself handles only the interface. Routing, data fetching and server rendering come from a framework, and the React team recommends starting a new project with one. Without a framework, you connect React to a bundler such as Vite and choose routing and data fetching yourself.
The interface is built from components arranged in a tree: the root component renders its children, and data flows down the tree through props. Every screen update goes through three steps. The trigger is the initial render or a call to a state’s set function. Render: React calls your components and works out what should be on the screen. Commit: React changes the DOM only where something differs; if the render result is the same, the DOM is left alone. Then the browser repaints the screen.
Rendering must be a pure calculation: given the same inputs, a component returns the same JSX and does not change objects or variables that existed before the render. Otherwise unpredictable bugs appear as the code grows. To make them visible, in StrictMode React calls every component twice during development. Side effects belong outside rendering: in event handlers, and synchronisation with external systems in effects (see the “Effects” section).
The component tree is not tied to a platform: in the browser it is rendered by react-dom, and on a phone by React Native, which uses native Android and iOS elements instead of HTML tags.
How it differs from Next.js and React Native
| Aspect | React | Next.js | React Native |
|---|---|---|---|
| What it is | a UI library | a React framework for full-stack web applications | a framework for Android and iOS apps built with React |
| What it provides | components, state, hooks | routing, server and build-time rendering, Server Components | access to platform APIs and native components |
| What the UI is made of | HTML elements: <div>, <button> | HTML elements, with some of the HTML arriving ready-made from the server | <View>, <Text>, <Image> — native views |
| Where it runs | in the browser | on the server and in the browser; can be exported as a static site | on the device |
For a new web application, choose Next.js or another framework. Use React with a bundler if no framework fits or you are learning the basics. For mobile apps, use React Native, usually through the Expo framework. For details, see the Next.js and React Native references.
What you need to know first
- JavaScript: functions and arrow functions,
importandexportmodules, destructuring, the array methodsmapandfilter— see the JavaScript reference. - HTML and CSS: tags, attributes, classes — see the HTML and CSS reference.
- TypeScript is optional. The examples use JavaScript components (
.jsx); in a TypeScript project you write them in.tsxfiles, and the TypeScript reference describes how to type props.
Section sources
the section is written from these pages- Render and Commitreact.dev/learn/render-and-commit(opens in a new tab)
- Understanding Your UI as a Treereact.dev/learn/understanding-your-ui-as-a-tree(opens in a new tab)
- Thinking in Reactreact.dev/learn/thinking-in-react(opens in a new tab)
- Creating a React Appreact.dev/learn/creating-a-react-app(opens in a new tab)
- Core Components and Native Componentsreactnative.dev/docs/intro-react-native-components(opens in a new tab)