React
In short
React is an open-source JavaScript library for building user interfaces from reusable components that update automatically when their data changes.
What is React?
React is a JavaScript library for building user interfaces, originally created at Facebook and now maintained as an open-source project. Instead of writing step-by-step instructions that change the page, you describe what the UI should look like for a given state, and React updates the browser's DOM to match whenever that state changes.
A React app is built from components: functions that receive inputs called props and return a description of the UI, usually written in JSX, an HTML-like syntax inside JavaScript. Components can keep their own state with hooks such as useState, and when that state changes, React runs the component again and applies only the necessary changes to the page.
Think of components as building blocks: small, self-contained pieces such as a button, a search box, or a product card that snap together into larger features. Because each piece is reusable and behaves predictably, teams can build and maintain complex interfaces like dashboards, social feeds, and online editors.
React is often called a framework, but on its own it is a library focused on rendering UI. Routing, data loading, and server rendering usually come from frameworks built on top of it, such as Next.js or React Router, which can render React components with CSR, SSR, or SSG. Modern React also supports Server Components, which run only on the server and send no JavaScript for themselves to the browser.
Key takeaways
- React is a JavaScript library for building user interfaces.
- UIs are made of reusable components that receive props and hold state.
- JSX lets you write HTML-like markup inside JavaScript.
- React updates only the parts of the DOM that actually changed.
- Frameworks built on React add routing, data loading, and server rendering.
Example
import { useState } from "react";
// A reusable component that keeps its own state
function LikeButton({ label }) {
const [likes, setLikes] = useState(0);
// Clicking updates the state, and React re-renders the button
return (
<button onClick={() => setLikes(likes + 1)}>
{label}: {likes}
</button>
);
}
// Components are used like HTML tags: <LikeButton label="Likes" />Readers ask
Is React a framework or a library?
React describes itself as a library because it focuses on rendering user interfaces and leaves routing, data loading, and builds to other tools. In everyday conversation it is often called a framework, and full frameworks such as Next.js are built on top of it.
What is JSX?
JSX is a syntax extension that lets you write HTML-like markup inside JavaScript, such as <button>Save</button>. A build tool compiles it into regular JavaScript function calls before it runs in the browser.
What is the difference between React and React Native?
React is used to build user interfaces that render to the DOM in web browsers. React Native uses the same components and ideas but renders to native iOS and Android views instead of HTML.
Often compared
- React vs VueReact is a library that uses JSX and leaves routing and state to its ecosystem, while Vue is a framework with HTML-like templates and official tools for both.
- React vs AngularReact is Meta's flexible UI library that you pair with other tools, while Angular is Google's opinionated framework with routing, forms and HTTP built in.
- Next.js vs ReactReact is a library for building UIs from components, while Next.js is a React framework that adds routing, server-side rendering and static generation.
See also
- JavaScriptWeb Development, p. 24JavaScript is the programming language that runs in web browsers to make pages interactive, and it also runs on servers through runtimes like Node.js.
- DOMWeb Development, p. 13The DOM is the browser's in-memory tree of objects representing a web page, which JavaScript can read and change to update what the user sees.
- SPAWeb Development, p. 41An SPA is a web application that loads a single HTML page and then updates content with JavaScript, so moving between views does not reload the page.
- FrameworkProgramming Fundamentals, p. 20A framework is a reusable foundation of code, tools, and conventions that provides the structure of an application, so developers only fill in their own logic.
- HydrationWeb Development, p. 22Hydration is the step where JavaScript in the browser takes over server-rendered HTML, attaching event handlers and state so the page becomes interactive.
- TypeScriptWeb Development, p. 50TypeScript is a programming language built on JavaScript that adds static types, catching many bugs before the code runs, and compiles to plain JavaScript.
- Next.jsWeb Development, p. 31Next.js is a React framework that adds routing, server-side rendering, static generation and server code, so a whole web app can be built as one project.
- JSXWeb Development, p. 26JSX is a JavaScript syntax extension for writing HTML-like markup inside code, used mainly with React to describe what the user interface should look like.
- State ManagementWeb Development, p. 44State management is how an application stores, updates and shares the data that changes while it runs, and keeps the interface in sync with it.
- React HooksWeb Development, p. 37React hooks are functions such as useState and useEffect that let a function component keep state, run side effects and share logic with others.
- UI ComponentWeb Development, p. 51A UI component is a self-contained, reusable piece of an interface, such as a button, a form or a card, that bundles its markup, style and behavior.
Spotted a mistake or something missing on this page?Suggest an edit