This document provides an introduction to React.js, including:
- React.js uses a virtual DOM for improved performance over directly manipulating the real DOM. Components are used to build up the UI and can contain state that updates the view on change.
- The Flux architecture is described using React with unidirectional data flow from Actions to Stores to Views via a Dispatcher. This ensures state changes in a predictable way.
- Setting up React with tools like Browserify/Webpack for module bundling is discussed, along with additional topics like PropTypes, mixins, server-side rendering and React Native.
42. Everything is a
component
• HTML is defined inside the component
• Component logic
• State is private
• Support parameters
• Events or callback for communication
43.
44.
45.
46. var Title = React.createClass({
render: function() {
return (
<h1>Hello React</h1>
);
}
});
var SubTitle = React.createClass({
render: function() {
return (
<h3>A library for web components</h3>
);
}
});
56. Virtual DOM
Javascript that access to the DOM is slow
console.dir(document.createElement('div'));
A DIV contains about 135 first level properties/function
(700 on second level).
A virtual DOM div element contains only 6 properties.
57. Virtual DOM
• Our code act on a fake DOM
• React.js takes care of generating a DOM patch
to update the real DOM
• Every ReactElement is a light, stateless,
immutable, virtual representation of a DOM
Element