React (software)
   HOME

TheInfoList



OR:

React (also known as React.js or ReactJS) is a
free and open-source Free and open-source software (FOSS) is a term used to refer to groups of software consisting of both free software and open-source software where anyone is freely licensed to use, copy, study, and change the software in any way, and the source ...
front-end JavaScript library for building user interfaces based on
components Circuit Component may refer to: •Are devices that perform functions when they are connected in a circuit.   In engineering, science, and technology Generic systems * System components, an entity with discrete structure, such as an assem ...
. It is maintained by
Meta Meta (from the Greek μετά, '' meta'', meaning "after" or "beyond") is a prefix meaning "more comprehensive" or "transcending". In modern nomenclature, ''meta''- can also serve as a prefix meaning self-referential, as a field of study or ende ...
(formerly Facebook) and a community of individual developers and companies. React can be used as a base in the development of single-page, mobile, or server-rendered applications with frameworks like
Next.js Next.js is an open-source web development framework created by Vercel enabling React (JavaScript library), React-based web applications with server-side scripting, server-side rendering and generating static web page, static websites. React docu ...
. However, React is only concerned with the user interface and rendering components to the
DOM Dom or DOM may refer to: People and fictional characters * Dom (given name), including fictional characters * Dom (surname) * Dom La Nena (born 1989), stage name of Brazilian-born cellist, singer and songwriter Dominique Pinto * Dom people, an et ...
, so creating React applications usually requires the use of additional libraries for routing, as well as certain client-side functionality.


Basic usage

The following is a rudimentary example of using React for the web, written in JSX and JavaScript. import React from 'react'; import ReactDOM from 'react-dom/client'; const Greeting = () => ; const App = () => ; const root = ReactDOM.createRoot(document.getElementById('root')); root.render( ); based on the HTML document below. React App
The Greeting function is a React component that displays the famous introductory ''Hello, world". When displayed in a web browser, the result will be a rendering of:

Hello, world!


Notable features


Declarative

React adheres to the
declarative programming In computer science, declarative programming is a programming paradigm—a style of building the structure and elements of computer programs—that expresses the logic of a computation without describing its control flow. Many languages that ap ...
paradigm (a 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 Circuit Component may refer to: •Are devices that perform functions when they are connected in a circuit.   In engineering, science, and technology Generic systems * System components, an entity with discrete structure, such as an assem ...
. These components are reusable and must be formed in the SRC folder following the Pascal Case as its naming convention (capitalize camelCase). Components can be rendered to a particular element in the
DOM Dom or DOM may refer to: People and fictional characters * Dom (given name), including fictional characters * Dom (surname) * Dom La Nena (born 1989), stage name of Brazilian-born cellist, singer and songwriter Dominique Pinto * Dom people, an et ...
using the React DOM library. When rendering a component, one can pass the values between components through "props": import React from "react"; import Tool from "./Tool"; const Example = () => ; export default Example; In the above example, the name property with the value "Gulshan" has been passed from the Example component to the Tool component. Also the return section is wrapped in a tag because there is a limitation in the return function, it can only return a single value. So all JSX elements and components are bound into a single tag. The two primary ways of declaring components in React are through function components and class-based components.


Functional components

Function components are declared with a function that then returns some JSX. From React 16.8 version and above, Functional component can use state using Hooks. const Greeter = () =>
Hello World
;


React hooks

On February 16, 2019, React 16.8 was released to the public. The release introduced React Hooks. Hooks are functions that let developers "hook into" React state and lifecycle features from function components. Hooks do not work inside classes — they let developers use React without classes. React provides a few built-in hooks like 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 rules of hooks which describe the characteristic code pattern that hooks rely on. It is the modern way to handle state with React. # Hooks should only be called at the top level (not inside loops or if statements). # Hooks should only be called from React function components and custom hooks, not normal functions or class components. Although these rules can't 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.


Class-based components

Class-based components are declared using ES6 classes. class ParentComponent extends React.Component Where class components are all about the use of classes and the lifecycle methods, functional components have hooks to deal with state management and other problems which arise when writing code in React.


Virtual DOM

Another notable feature is the use of a virtual Document Object Model, or virtual DOM. React creates an
in-memory An in-memory database (IMDB, or main memory database system (MMDB) or memory resident database) is a database management system that primarily relies on main memory for computer data storage. It is contrasted with database management systems that e ...
data-structure cache, computes the resulting differences, and then updates the browser's displayed DOM efficiently. This process is called reconciliation. This allows the programmer to write code as if the entire page is rendered on each change, while the React libraries only render subcomponents that actually change. This selective rendering provides a major performance boost. It saves the effort of recalculating the CSS style, layout for the page and rendering for the entire page.


Updates

When ReactDOM.render is called again for the same component and target, React takes the existing virtual DOM it knows about last time it rendered the element tree, compares it to whatever new thing developers want to render, and determines which (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 Dom or DOM may refer to: People and fictional characters * Dom (given name), including fictional characters * Dom (surname) * Dom La Nena (born 1989), stage name of Brazilian-born cellist, singer and songwriter Dominique Pinto * Dom people, an et ...
node). This is commonly used to trigger data loading from a remote source via an API. *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 Syntax Extension, 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). JSX is similar to another extension syntax created by Facebook for PHP called XHP. An example of JSX code: class App extends React.Component


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.


Server-Side Rendering

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 server-side rendering, 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 server-side rendering, 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 (SEO) purposes. const express = require('express'); const React = require('react'); const = require('react-dom/server'); const app = express(); app.get('/', (req, res) => ); app.listen(3000, () => );


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 (which might be contrasted with
AngularJS AngularJS is a discontinued free and open-source JavaScript-based web framework for developing single-page applications. It was maintained mainly by Google and a community of individuals and corporations. It aimed to simplify both the development ...
's bidirectional flow), the Flux architecture was developed as an alternative to the popular
model–view–controller Model–view–controller (MVC) is a software architectural pattern commonly used for developing user interfaces that divide the related program logic into three interconnected elements. This is done to separate internal representations of infor ...
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.


Future development

Project status can be tracked via the core team discussion forum. However, major changes to React go through the Future of React repository issues and pull requests. This enables the React community to provide feedback on new potential features, experimental APIs and JavaScript syntax improvements.


History

React was created by Jordan Walke, a software engineer at
Meta Meta (from the Greek μετά, '' meta'', meaning "after" or "beyond") is a prefix meaning "more comprehensive" or "transcending". In modern nomenclature, ''meta''- can also serve as a prefix meaning self-referential, as a field of study or ende ...
, who released an early prototype of React called "FaxJS". He was influenced by XHP, an HTML component library for PHP. It was first deployed on Facebook's
News Feed On the World Wide Web, a web feed (or news feed) is a data format used for providing users with frequently updated content. Content distributors ''syndicate'' a web feed, thereby allowing users to ''subscribe'' a channel to it by adding the feed ...
in 2011 and later on
Instagram Instagram is a photo and video sharing social networking service owned by American company Meta Platforms. The app allows users to upload media that can be edited with filters and organized by hashtags and geographical tagging. Posts can ...
in 2012. It was open-sourced at JSConf US in May 2013. React Native, which enables native
Android Android may refer to: Science and technology * Android (robot), a humanoid robot or synthetic organism designed to imitate a human * Android (operating system), Google's mobile operating system ** Bugdroid, a Google mascot sometimes referred to ...
, iOS, and UWP development with React, was announced at Facebook's React Conf in February 2015 and open-sourced in March 2015. On April 18, 2017, Facebook announced React Fiber, a new set of internal algorithms for rendering, as opposed to React's old rendering algorithm, Stack. React Fiber was to become the foundation of any future improvements and feature development of the React library. The actual syntax for programming with React does not change; only the way that the syntax is executed has changed. React's old rendering system, Stack, was developed at a time when the focus of the system on dynamic change was not understood. Stack was slow to draw complex animation, for example, trying to accomplish all of it in one chunk. Fiber breaks down animation into segments that can be spread out over multiple frames. Likewise, the structure of a page can be broken into segments that may be maintained and updated separately. JavaScript functions and virtual
DOM Dom or DOM may refer to: People and fictional characters * Dom (given name), including fictional characters * Dom (surname) * Dom La Nena (born 1989), stage name of Brazilian-born cellist, singer and songwriter Dominique Pinto * Dom people, an et ...
objects are called "fibers", and each can be operated and updated separately, allowing for smoother on-screen rendering. On September 26, 2017, React 16.0 was released to the public. On August 10, 2020, the React team announced the first release candidate for React v17.0, notable as the first major release without major changes to the React developer-facing API. On March 29, 2022, React 18 was released which introduced a new concurrent renderer, automatic batching and support for server side rendering with Suspense.


Licensing

The initial public release of React in May 2013 used the Apache License 2.0. In October 2014, React 0.12.00 replaced this with the
3-clause BSD license BSD licenses are a family of permissive free software licenses, imposing minimal restrictions on the use and distribution of covered software. This is in contrast to copyleft licenses, which have share-alike requirements. The original BSD lice ...
and added a separate PATENTS text file that permits usage of any Facebook patents related to the software:
The license granted hereunder will terminate, automatically and without notice, for anyone that makes any claim (including by filing any lawsuit, assertion or other action) alleging (a) direct, indirect, or contributory infringement or inducement to infringe any patent: (i) by Facebook or any of its subsidiaries or affiliates, whether or not such claim is related to the Software, (ii) by any party if such claim arises in whole or in part from any software, product or service of Facebook or any of its subsidiaries or affiliates, whether or not such claim is related to the Software, or (iii) by any party relating to the Software; or (b) that any right in any patent claim of Facebook is invalid or unenforceable.
This unconventional clause caused some controversy and debate in the React user community, because it could be interpreted to empower Facebook to revoke the license in many scenarios, for example, if Facebook sues the licensee prompting them to take "other action" by publishing the action on a blog or elsewhere. Many expressed concerns that Facebook could unfairly exploit the termination clause or that integrating React into a product might complicate a startup company's future acquisition. Based on community feedback, Facebook updated the patent grant in April 2015 to be less ambiguous and more permissive:
The license granted hereunder will terminate, automatically and without notice, if you (or any of your subsidiaries, corporate affiliates or agents) initiate directly or indirectly, or take a direct financial interest in, any Patent Assertion: (i) against Facebook or any of its subsidiaries or corporate affiliates, (ii) against any party if such Patent Assertion arises in whole or in part from any software, technology, product or service of Facebook or any of its subsidiaries or corporate affiliates, or (iii) against any party relating to the Software. ..A "Patent Assertion" is any lawsuit or other action alleging direct, indirect, or contributory infringement or inducement to infringe any patent, including a cross-claim or counterclaim.
The
Apache Software Foundation The Apache Software Foundation (ASF) is an American nonprofit corporation (classified as a 501(c)(3) organization in the United States) to support a number of open source software projects. The ASF was formed from a group of developers of the A ...
considered this licensing arrangement to be incompatible with its licensing policies, as it "passes along risk to downstream consumers of our software imbalanced in favor of the licensor, not the licensee, thereby violating our Apache legal policy of being a universal donor", and "are not a subset of those found in the
pache License 2.0 Pache is a surname. Notable people with this surname include: * Claude Pache (born 1943), French rower *Cristian Pache (born 1998), Dominican professional baseball outfielder *François Pache (born 1932), Swiss figure skater *Jean-Nicolas Pache (17 ...
and they cannot be sublicensed as
pache License 2.0 Pache is a surname. Notable people with this surname include: * Claude Pache (born 1943), French rower *Cristian Pache (born 1998), Dominican professional baseball outfielder *François Pache (born 1932), Swiss figure skater *Jean-Nicolas Pache (17 ...
. In August 2017, Facebook dismissed the Apache Foundation's downstream concerns and refused to reconsider their license. The following month, WordPress decided to switch its Gutenberg and Calypso projects away from React. On September 23, 2017, Facebook announced that the following week, it would re-license Flow,
Jest A joke is a display of humour in which words are used within a specific and well-defined narrative structure to make people laugh and is usually not meant to be interpreted literally. It usually takes the form of a story, often with dialogue, ...
, React, and Immutable.js under a standard MIT License; the company stated that React was "the foundation of a broad ecosystem of open source software for the web", and that they did not want to "hold back forward progress for nontechnical reasons". On September 26, 2017, React 16.0.0 was released with the MIT license. The MIT license change has also been backported to the 15.x release line with React 15.6.2.


See also

* Angular (web framework) *
Backbone.js Backbone.js is a JavaScript rich-client web app framework based on the model–view–controller design paradigm, intended to connect to an API over a RESTful JSON interface. Backbone is known for being lightweight, as its only hard dependency i ...
*
Ember.js Ember.js is an open-source JavaScript web framework that utilizes a component-service pattern. It allows developers to create scalable single-page web applications by incorporating common idioms, best practices, and patterns from other single-pa ...
* Gatsby (JavaScript framework) *
Next.js Next.js is an open-source web development framework created by Vercel enabling React (JavaScript library), React-based web applications with server-side scripting, server-side rendering and generating static web page, static websites. React docu ...
*
Svelte Svelte is a free and open-source front end component framework or language created by Rich Harris and maintained by the Svelte core team members. Svelte is not a monolithic JavaScript library imported by applications: instead, Svelte compiles H ...
* Vue.js *
Comparison of JavaScript libraries This is a comparison of web frameworks for front-end web development that are heavily reliant on JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wi ...
*
Web Components Web Components are a set of features that provide a standard component model for the Web allowing for encapsulation and interoperability of individual HTML elements. Primary technologies used to create them include: * Custom Elements: APIs to ...


References


External links

* {{Authority control 2015 software Ajax (programming) Facebook software JavaScript libraries Software using the MIT license Web applications