Created , updated

React is a JavaScript library for building user interfaces from Facebook. You can think of it as the "V" (or the "VC") in MVC. It can be used in concert with other libraries such as Backbone.

Core ideas

Many web apps pursue a separation of concerns by putting markup in templates, logic in JavaScript files, and presentational styling in CSS. There is a strong sense in which this is actually just "separation of technologies".

React, on the other hand, freely mixes markup and logic (and even styling) inside the JavaScript using a layer of syntactic sugar called JSX that gets pre-processed away. This is reminiscent of the Objective-C approach to MVC in Apple’s APIs, where views (NSView and UIView instances) comprise a lot of code and logic.

The key advantages of the approach stem from the fact that this code is used to generate a synthetic representation of the DOM and the event system. This representation can be manipulated very quickly, with the result diffed against the real DOM and only the minimal set of changes necessary to synchronize are applied, making it very fast.

This speed-up also leads to a great reduction in complexity, because it means that you can write your views in a declarative style which states in simple terms how they should be rendered; updating just means calling the (basically idempotent) render() method again. Even complex hierarchies can be re-rendered frequently, because only the minimal underlying changes will be propagated to the DOM.

Additionally the synthetic events system obviates the need for maintaining bulky cross-browser events code. (Notably, some polyfills are required for supporting older browsers, but React doesn’t bundle any, enabling people to pick and choose their polyfill implementation.)

Official links

Using React with Backbone