React (also known as React.js or ReactJS) is a free and open-source front-end JavaScript library that aims to make building user interfaces based on components more "seamless". It is maintained by a community of individual developers and companies and governed by the React Foundation, an independent foundation hosted by the Linux Foundation. According to the 2025 Stack Overflow Developer Survey, React is one of the most commonly used web technologies.

React can be used to develop single-page, mobile, or server-rendered applications with frameworks like Next.js and React Router. Because React is only concerned with the user interface and rendering components to the DOM, React applications often rely on libraries for routing and other client-side functionality. A key advantage of React is that it only re-renders those parts of the page that have changed, avoiding unnecessary re-rendering of unchanged DOM elements. React is used by an estimated 6.1% of all websites.

Features Declarative React adheres to the declarative programming paradigm. Developers design views for each state of an application, and React updates and renders components when data changes. This is in contrast with imperative programming.

Components React code is made of entities called components. These components are modular and can be reused. React applications typically consist of many layers of components. The components are rendered to a root element in the DOM using the React DOM library. When rendering a component, values are passed between components through props (short for "properties"). Values internal to a component are called its state.

The two primary ways of declaring components in React are through function components and class components. Since React v16.8, using function components is the recommended way.

Function components Function components are JavaScript functions that return JSX or other React nodes. They can receive information from parent components through props and use Hooks to access React features such as state. Function components can use internal state with the useState Hook.

React Hooks On February 16, 2019, React 16.8 was released to the public, introducing React Hooks. Hooks are functions that let developers "hook into" React state and lifecycle features from function components. Notably, Hooks do not work inside classes — they let developers use more features of React without classes.

React provides several built-in hooks such as useState, useContext, useReducer, useMemo and useEffect. Others are documented in the Hooks API Reference. useState and useEffect, which are the most commonly used, are for controlling state and side effects, respectively. React also provides Hooks for refs, effects, performance optimization, and integration with external stores. These include useRef, useTransition, useDeferredValue, useSyncExternalStore, and, in React 19.2, useEffectEvent. Hooks also provide a way to share stateful logic between components without changing their component hierarchy. The React team describes Hooks as the favored way to share logic between components, reducing the need for patterns such as render props and higher-order components.

Rules of hooks There are two rules of hooks which describe the characteristic code patterns that hooks rely on:

"Only call hooks at the top level" — do not call hooks from inside loops, conditions, or nested statements so that the hooks are called in the same order each render. "Only call hooks from React functions" — do not call hooks from plain JavaScript functions so that stateful logic stays with the component.

Although these rules cannot be enforced at runtime, code analysis tools such as linters can be configured to detect many mistakes during development. The rules apply to both usage of Hooks and the implementation of custom Hooks, which may call other Hooks.

Server components React Server Components (RSC) are function components that run exclusively on the server. The concept was first introduced in the talk "Data Fetching with Server Components". Currently, server components are most readily usable with Next.js. With Next.js, it's possible to write components for both the server and the client (browser). When a server rendered component is received by the browser, React in the browser takes over and creates the virtual DOM and attaches event handlers. This is called hydration.

Though a similar concept to Server Side Rendering, RSCs do not send corresponding JavaScript to the client as no hydration occurs. As a result, they have no access to hooks. However, they may be asynchronous function, allowing them to directly perform asynchronous operations:

async function MyComponent() { const message = await fetchMessageFromDb();

return ( <div>Message: {message}</div> ); }

React Server Components became stable in React 19. They can render ahead of time in an environment separate from the client application, either at build time or on a web server for each request. Server Components can access server-side data sources and pass data and JSX to Client Components.

React also supports Server Functions, which allow Client Components to call asynchronous functions executed on the server. Server Functions can be marked with the "use server" directive and can be defined in Server Components or imported into Client Components.

Class components Class components are declared using ES6 classes. They behave the same way that function components do, but instead of using Hooks to manage state and lifecycle events, they use the lifecycle methods on the React.Component base class. class ParentComponent extends React.Component { state = { color: 'green' }; render() { return ( <ChildComponent color={this.state.color} /> );

Class components are still supported, but React recommends defining new components as functions instead of classes.

Routing React itself does not come with built-in support for routing. React is primarily a library for building user interfaces, and it does not include a full-fledged routing solution out of the box. Third-party libraries can be used to handle routing in React applications, such as React Router. It allows the developer to define routes, manage navigation, and handle URL changes in a React-friendly way.

For full-stack applications, the React documentation recommends using a React framework such as Next.js or React Router, which provide routing and other application-level features that React itself does not prescribe.

Virtual DOM Another notable feature is the use of a virtual Document Object Model, or Virtual DOM. React creates an in-memory data-structure, similar to the browser DOM. Every time components are rendered, the result is compared with the virtual DOM. It then updates the browser's displayed DOM efficiently with only the computed differences. This process is called reconciliation. This allows the programmer to write code as if the entire page is rendered on each change, while React only renders the components that actually change. This selective rendering provides a major performance boost.

Updates When ReactDOM.render is called again for the same component and target, React represents the new UI state in the Virtual DOM and determines which parts (if any) of the living DOM needs to change.

Lifecycle methods Lifecycle methods for class-based components use a form of hooking that allows the execution of code at set points during a component's lifetime. ShouldComponentUpdate allows the developer to prevent unnecessary re-rendering of a component by returning false if a render is not required. componentDidMount is called once the component has "mounted" (the component has been created in the user interface, often by associating it with a DOM node). This is commonly used to trigger data loading from a remote source via an API. componentDidUpdate is invoked immediately after updating occurs. componentWillUnmount is called immediately before the component is torn down or "unmounted". This is commonly used to clear resource-demanding dependencies to the component that will not simply be removed with the unmounting of the component (e.g., removing any setInterval() instances that are related to the component, or an "eventListener" set on the "document" because of the presence of the component) render is the most important lifecycle method and the only required one in any component. It is usually called every time the component's state is updated, which should be reflected in the user interface.

JSX

JSX, or JavaScript XML, is an extension to the JavaScript language syntax. Similar in appearance to HTML, JSX provides a way to structure component rendering using syntax familiar to many developers. React components are typically written using JSX, although they do not have to be (components may also be written in pure JavaScript). During compilation, JSX is converted to JavaScript code. JSX is similar to another extension syntax created by Facebook for PHP called XHP.

An example of JSX code: function Example() { // Declare a new state variable, which we'll call "count" const [count, setCount] = useState(0);

return ( <div> <p>You clicked {count} times</p> <button onClick={() => setCount(count + 1)}> Click me </button> </div> ); }

Architecture beyond HTML The basic architecture of React applies beyond rendering HTML in the browser. For example, Facebook has dynamic charts that render to <canvas> tags, and Netflix and PayPal use universal loading to render identical HTML on both the server and client. React can also be used to develop native apps for Android and iOS using React Native.

Server-side rendering Server-side rendering (SSR) refers to the process of rendering a client-side JavaScript application on the server, rather than in the browser. This can improve the performance of the application, especially for users on slower connections or devices.

With SSR, the initial HTML that is sent to the client includes the fully rendered UI of the application. This allows the client's browser to display the UI immediately, rather than having to wait for the JavaScript to download and execute before rendering the UI.

React supports SSR, which allows developers to render React components on the server and send the resulting HTML to the client. This can be useful for improving the performance of the application, as well as for search engine optimization purposes.

Common idioms React does not attempt to provide a complete application library. It is designed specifically for building user interfaces, and therefore does not include many of the tools some developers might consider necessary to build an application; this allows the developer the choice of software libraries to accomplish tasks, such as performing network access or local data storage.

Unidirectional data flow

To support React's concept of unidirectional data flow (which might be contrasted with AngularJS's bidirectional flow), the Flux architecture was developed as an alternative to the popular model–view–controller architecture. Flux features actions which are sent through a central dispatcher to a store, and changes to the store are propagated back to the view. When used with React, this propagation is accomplished through component properties. Since its conception, Flux has been superseded by libraries such as Redux and MobX.

Flux can be considered a variant of the observer pattern.