React (software)
React 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 Meta and a community of individual developers and companies. 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% 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 ''. 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, announced at React Conf 2018, and available since React v16.8, are declared with a function that accepts a single "props" argument and returns JSX. Function components can use internal state with theuseState 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.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.
Server components
React Server Components 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. 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
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 theReact.Component base class.class ParentComponent extends React.Component
This trend aligns with the broader industry movement towards functional programming and modular design. As React continues to evolve, it is essential for developers to consider the benefits of functional components and React Hooks when building new applications or refactoring existing ones.
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.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
WhenReactDOM.render is called again for the same component and target, React represents the new UI state in the Virtual DOM and determines which parts 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.-
ShouldComponentUpdateallows the developer to prevent unnecessary re-rendering of a component by returning false if a render is not required. -
componentDidMountis called once the component has "mounted". This is commonly used to trigger data loading from a remote source via an API. -
componentDidUpdateis invoked immediately after updating occurs. -
componentWillUnmountis 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 -
renderis 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
An example of JSX code:
function Example
Architecture beyond HTML
The basic architecture of React applies beyond rendering HTML in the browser. For example, Facebook has dynamic charts that render to 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
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 choice of whichever libraries the developer prefers to accomplish tasks such as performing network access or local data storage. Common patterns of usage have emerged as the library matures.Unidirectional data flow
To support React's concept of unidirectional data 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.
A React component under the Flux architecture should not directly modify any props passed to it, but should be passed callback functions that create actions which are sent by the dispatcher to modify the store. The action is an object whose responsibility is to describe what has taken place: for example, an action describing one user "following" another might contain a user id, a target user id, and the type
USER_FOLLOWED_ANOTHER_USER. The stores, which can be thought of as models, can alter themselves in response to actions received from the dispatcher.This pattern is sometimes expressed as "properties flow down, actions flow up". Many implementations of Flux have been created since its inception, perhaps the most well-known being Redux, which features a single store, often called a single source of truth.
In February 2019,
useReducer was introduced as a [|React hook] in the 16.8 release. It provides an API that is consistent with Redux, enabling developers to create Redux-like stores that are local to component states.