Questions tagged [reactjs]

React is a JavaScript library for building user interfaces. It uses a declarative, component-based paradigm and aims to be both efficient and flexible.

React is a library for building user interfaces.

Declarative

React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes.

Declarative views make your code more predictable and easier to debug.

Component-Based

Build encapsulated components that manage their own state, then compose them to make complex UIs.

Since component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep state out of the DOM.

Learn Once, Write Anywhere

We don’t make assumptions about the rest of your technology stack, so you can develop new features in React without rewriting existing code.

React can also render on the server using Node and power mobile apps using .


Just the UI

Lots of people use React as the V in MVC. React makes no assumptions about the rest of your technology stack, and it's easy to try it out on a small feature in an existing project.


Virtual DOM

React uses a virtual DOM diff implementation for ultra-high performance. It can also render on the server using — a heavy browser DOM isn't required. Further, there is a React-Native offshoot for using React on mobile devices such as and .


Data flow

React implements one-way reactive data flow using props which reduce boilerplate and is easier to understand than traditional two-way data binding.


Example using JSX

class HelloWorldWidget extends React.Component {
    render() {
        return (
            <div>
                Hello World!
            </div>
        );
    }
};

ReactDOM.render(
    <HelloWorldWidget />,
    document.body
);

Example using functional component

const HelloWorldWidget = () => {
    return (
        <div>
            Hello World!
        </div>
    );
};

ReactDOM.render(
    <HelloWorldWidget />,
    document.body
);

Getting started

 npx create-react-app my_app

Advantages

  • React creates a virtual DOM so that all the components can be re-rendered individually without the need for the whole page to be repainted by the browser

  • A user can update a particular content of the page just by re-rendering only that component

  • React's view logic means it can easily render on the server, in the browser or native components

  • React can be used in conjunction with frameworks like and

  • Separating the declarative view () and logic make projects easier to read and maintain


Resources:


Books:


Related tags:


Official Logo:

React logo


Versions:

Note: The table below provides a summary of changes for each version only. A comprehensive list of changes for each version can be found here.

Version Release Date Changes
17.0.2 22 March 2021 Remove unused dependency to address the SharedArrayBuffer cross-origin isolation warning.
17.0.1 22 October 2020 React DOM - Fix a crash in IE11.
17.0.0 20 October 2020 React - Add react/jsx-runtime and react/jsx-dev-runtime for the new JSX transform.Build component stacks from native error frames. Allow to specify displayName on context for improved stacks. Prevent 'use strict' from leaking in the UMD bundles. Stop using fb.me for redirects.... React DOM - Delegate events to roots instead of document. Clean up all effects before running any next effects. Run useEffect cleanup functions asynchronously.
16.14.1 14 October 2020 Add support for the new JSX transform.
16.13.1 19 March 2020 Fix bug in legacy mode Suspense where effect clean-up functions are not fired. Revert warning for cross-component updates that happen inside class render lifecycles.
16.13.0 26 February 2020 Features added in React Concurrent mode. Fix regressions in React core library and React Dom.
16.12.0 14 November 2019 React DOM - Fix passive effects (useEffect) not being fired in a multi-root app.React Is - Fix lazy and memo types considered elements instead of components
16.11.0 22 October 2019 Fix mouseenter handlers from firing twice inside nested React containers. Remove unstable_createRoot and unstable_createSyncRoot experimental APIs. (These are available in the Experimental channel as createRoot and createSyncRoot.)
16.10.2 3 October 2019 Fix regression in react-native-web by restoring order of arguments in event plugin extractors
16.10.1 28 September 2019 Fix regression in Next.js apps by allowing Suspense mismatch during hydration to silently proceed.
16.10.0 27 September 2019 Fix edge case where a hook update wasn't being memoized. Fix heuristic for determining when to hydrate, so we don't incorrectly hydrate during an update. Clear additional fiber fields during unmount to save memory. Fix bug with required text fields in Firefox. Prefer Object.is instead of inline polyfill, when available. Fix bug when mixing Suspense and error handling.
16.9.0 9 August 2019 Add <React.Profiler> API for gathering performance measurements programmatically. Remove unstable_ConcurrentMode in favor of unstable_createRoot.
16.8.6 27 March 2019 Fix an incorrect bailout in useReducer(), Fix iframe warnings in Safari DevTools, Warn if contextType is set to Context.Consumer instead of Context, Warn if contextType is set to invalid values.
16.8.0 06 February 2019 Add Hooks, Add ReactTestRenderer.act() and ReactTestUtils.act() for batching updates, Support synchronous thenables passed to React.lazy(), Improve useReducer Hook lazy initialization API.
16.7.0 20 December 2018 Fix performance of React.lazy for lazily-loaded components, Clear fields on unmount to avoid memory leaks, Fix bug with SSR, Fix a performance regression.
16.6.0 23 October 2018 Add support for contextType, Support priority levels, continuations, and wrapped callbacks, Improve the fallback mechanism, Fix gray overlay on iOS Safari, Add React.lazy() for code splitting components.
16.5.0 05 September 2018 Add support for React DevTools Profiler, Handle errors in more edge cases gracefully, Add react-dom/profiling, Add onAuxClick event for browsers, Add movementX and movementY fields to mouse events, Add tangentialPressure and twist fields to pointer event.
16.4.0 24 May 2018 Add support for Pointer Events specification, Add the ability to specify propTypes, Fix reading context, Fix the getDerivedStateFromProps() support, Fix a testInstance.parent crash, Add React.unstable_Profiler component for measuring performance, Change internal event names.
16.3.2 16 April 2018 Fix an IE crash, Fix labels in User Timing measurements, Add a UMD build, Improve performance of unstable_observedBits API with nesting.
16.3.1 03 April 2018 Prefix private API, Fix performance regression and error handling bugs in development mode, Add peer dependency, Fix a false positive warning in IE11 when using Fragment.
16.3.0 29 March 2018 Add a new officially supported context API, Add new packagePrevent an infinite loop when attempting to render portals with SSR, Fix an issue with this.state, Fix an IE/Edge issue.
16.1.0 9 November 2017 Discontinuing Bower Releases, Fix an accidental extra global variable in the UMD builds, Fix onMouseEnter and onMouseLeave firing, Fix <textarea> placeholder, Remove unused code, Add a missing package.json dependency, Add support for React DevTools.
16.0.0 26 September 2017 Improved error handling with introduction of "error boundaries", React DOM allows passing non-standard attributes, Minor changes to setState behavior, remove react-with-addons.js build, Add React.createClass as create-react-class, React.PropTypes as prop-types, React.DOM as react-dom-factories, changes to the behavior of scheduling and lifecycle methods.
15.6.0 13 June 2017 Add support for CSS variables in style attribute and Grid style properties, Fix AMD support for addons depending on react, Remove unnecessary dependency, Add a deprecation warning for React.createClass and React.DOM factory helpers.
15.5.4 11 April 2017 Fix compatibility with Enzyme by exposing batchedUpdates on shallow renderer, Update version of prop-types, Fix react-addons-create-fragment package to include loose-envify transform.
15.5.0 07 April 2017 Added react-dom/test-utils, Removed peerDependencies, Fixed issue with Closure Compiler, Added a deprecation warning for React.createClass and React.PropTypes, Fixed Chrome bug.
15.4.2 06 January 2017 Fixed build issues, Added missing package dependencies, Improved error messages.
15.4.1 23 November 2016 Restructure variable assignment, Fixed event handling, Fixed compatibility of browser build with AMD environments.
15.4.0 16 November 2016 React package and browser build no longer includes React DOM, Improved development performance, Fixed occasional test failures, update batchedUpdates API, React Perf, and ReactTestRenderer.create().
15.3.1 19 August 2016 Improve performance of development builds, Cleanup internal hooks, Upgrade fbjs, Improve startup time of React, Fix memory leak in server rendering, fix React Test Renderer, Change trackedTouchCount invariant into a console.error.
15.3.0 30 July 2016 Add React.PureComponent, Fix issue with nested server rendering, Add xmlns, xmlnsXlink to support SVG attributes and referrerPolicy to HTML attributes, updates React Perf Add-on, Fixed issue with ref.
15.2.0 01 July 2016 Include component stack information, Stop validating props at mount time, Add React.PropTypes.symbol, Add onLoad handling to <link> and onError handling to <source> element, Add isRunning() API, Fix performance regression.
15.1.0 20 May 2016 Fix a batching bug, Ensure use of the latest object-assign, Fix regression, Remove use of merge utility, Renamed some modules.
15.0.0 07 April 2016 Initial render now uses document.createElement instead of generating HTML, No more extra <span>s, Improved SVG support, ReactPerf.getLastMeasurements() is opaque, New deprecations introduced with a warning, Fixed multiple small memory leaks, React DOM now supports the cite and profile HTML attributes and cssFloat, gridRow and gridColumn CSS properties.
0.14.1 29 October 2015 Added support for srcLang, default, kind attributes, and color attribute, Ensured legacy .props access on DOM nodes, Fixed scryRenderedDOMComponentsWithClass, Added react-dom.js.
0.13.0 10 March 2015 Deprecated patterns that warned in 0.12 no longer work, ref resolution order has changed, Removed properties this._pendingState and this._rootNodeID, Support ES6 classes, Added API React.findDOMNode(component), Support for iterators and immutable-js sequences, Added new features React.addons.createFragment, deprecated React.addons.classSet.
0.12.0 21 November 2014 Added new features Spread operator ({...}) introduced to deprecate this.transferPropsTo, Added support for acceptCharset, classID, manifest HTML attributes, React.addons.batchedUpdates added to API, @jsx React.DOM no longer required, Fixed issues with CSS Transitions.
0.11.0 17 July 2014 Improved SVG support, Normalized e.view event, Update $apply command, Added support for namespaces, Added new transformWithDetails API, includes pre-built packages under dist/, MyComponent() now returns a descriptor, not an instance.
0.10.0 21 March 2014 Added support for srcSet and textAnchor attributes, add update function for immutable data, Ensure all void elements don't insert a closing tag.
0.9.0 20 February 2014 Added support for crossOrigin, download and hrefLang, mediaGroup and muted, sandbox, seamless, and srcDoc, scope attributes, Added any, arrayOf, component, oneOfType, renderable, shape to React.PropTypes, Added support for onMouseOver and onMouseOut event, Added support for onLoad and onError on <img> elements.
0.8.0 20 December 2013 Added support for rows & cols, defer & async, loop for <audio> & <video>, autoCorrect attributes. Added onContextMenu events, Upgraded jstransform and esprima-fb tools, Upgraded browserify.
0.5.0 20 October 2013 Improve Memory usage, Support for Selection and Composition events, Support for getInitialState and getDefaultProps in mixins, Added React.version and React.isValidClass, Improved compatibility for Windows.
0.4.0 20 July 2013 Support for comment nodes <div>{/* */}</div>, Improved server-side rendering APIs, Removed React.autoBind, Support for the key prop, Improvements to forms, Fixed bugs.
0.3.0 29 May 2013 Initial Public Release

307684 questions
1771
votes
36 answers

Programmatically navigate using React router

With react-router I can use the Link element to create links which are natively handled by react router. I see internally it calls this.context.transitionTo(...). I want to do a navigation. Not from a link, but from a dropdown selection (as an…
George Mauer
  • 103,465
  • 117
  • 349
  • 581
1508
votes
72 answers

Loop inside React JSX

I'm trying to do something like the following in React JSX (where ObjectRow is a separate component): for (var i=0; i < numrows; i++) { } I realize and understand why this isn't valid JSX, since JSX…
B Robster
  • 34,955
  • 14
  • 82
  • 116
1124
votes
8 answers

Why use Redux over Facebook Flux?

I've read this answer, reducing boilerplate, looked at few GitHub examples and even tried redux a little bit (todo apps). As I understand, official redux doc motivations provide pros comparing to traditional MVC architectures. BUT it doesn't…
VB_
  • 43,322
  • 32
  • 111
  • 238
1112
votes
30 answers

What do these three dots in React do?

What does the ... do in this React (using JSX) code and what is it called?
Thomas Johansen
  • 11,423
  • 3
  • 10
  • 17
1091
votes
27 answers

How to pass props to {this.props.children}

I'm trying to find the proper way to define some components which could be used in a generic way: There is a logic going on for rendering between parent and children components of course,…
plus-
  • 40,996
  • 14
  • 55
  • 71
879
votes
45 answers

What is the difference between React Native and React?

I have started to learn React out of curiosity and wanted to know the difference between React and React Native - though could not find a satisfactory answer using Google. React and React Native seems to have the same format. Do they have completely…
shiva kumar
  • 10,194
  • 4
  • 20
  • 24
860
votes
50 answers

React-router urls don't work when refreshing or writing manually

I'm using React-router and it works fine while I'm clicking on link buttons, but when I refresh my webpage it does not load what I want. For instance, I am in localhost/joblist and everything is fine because I arrived here pressing a link. But If I…
DavidDev
  • 8,865
  • 3
  • 12
  • 15
814
votes
20 answers

Can you force a React component to rerender without calling setState?

I have an external (to the component), observable object that I want to listen for changes on. When the object is updated it emits change events, and then I want to rerender the component when any change is detected. With a top-level React.render…
Philip Walton
  • 26,214
  • 15
  • 55
  • 81
794
votes
16 answers

Understanding unique keys for array children in React.js

I'm building a React component that accepts a JSON data source and creates a sortable table. Each of the dynamic data rows has a unique key assigned to it but I'm still getting an error of: Each child in an array should have a unique "key" prop. …
Brett DeWoody
  • 50,328
  • 25
  • 121
  • 168
781
votes
11 answers

Why do we need middleware for async flow in Redux?

According to the docs, "Without middleware, Redux store only supports synchronous data flow". I don't understand why this is the case. Why can't the container component call the async API, and then dispatch the actions? For example, imagine a…
sbichenko
  • 11,613
  • 7
  • 43
  • 81
733
votes
28 answers

How to set focus on an input field after rendering?

What's the react way of setting focus on a particular text field after the component is rendered? Documentation seems to suggest using refs, e.g: Set ref="nameInput" on my input field in the render function, and then…
Dave
  • 9,212
  • 5
  • 27
  • 41
731
votes
35 answers

React js onClick can't pass value to method

I want to read the onClick event value properties. But when I click on it, I see something like this on the console: SyntheticMouseEvent {dispatchConfig: Object, dispatchMarker: ".1.1.0.2.0.0:1", nativeEvent: MouseEvent, type: "click", target My…
user1924375
  • 8,871
  • 6
  • 17
  • 27
715
votes
15 answers

How do I conditionally add attributes to React components?

Is there a way to only add attributes to a React component if a certain condition is met? I'm supposed to add required and readOnly attributes to form elements based on an Ajax call after render, but I can't see how to solve this since…
Remi Sture
  • 8,859
  • 4
  • 18
  • 33
657
votes
7 answers

What is the difference between using constructor vs getInitialState in React / React Native?

I've seen both used interchangeably. What are the main use cases for both? Are there advantages / disadvantages? Is one a better practice?
Nader Dabit
  • 47,131
  • 13
  • 103
  • 88
655
votes
9 answers

How to get first N number of elements from an array

I am working with Javascript(ES6) /FaceBook react and trying to get the first 3 elements of an array that varies in size. I would like do the equivalent of Linq take(n). In my Jsx file I have the following: var items = list.map(i => { return ( …
user1526912
  • 10,370
  • 11
  • 49
  • 81
1
2 3
99 100