Table of Contents

About

React is a virtual dom technology that permits to create HTML page or components based on the concepts that:

  • If the data (state) changes, the UI should change too.
  • Learn once, write anywhere

Most of the example use Babel as Javascript language. Babel offers support:

Inventor: Jordan Walke ??

Example

Native Javascript

In Native Javascript, in the browser with createElement

ReactDOM.render(
  React.createElement(
     'h1',
     {className: 'hallo'},
     'Hello, world!'
  ),
  document.getElementById('root')
);
<div id="root">
  <!-- This div's content will be managed by React. -->
</div>

In Jsx

In jsx where the createElement is replaced by XHTML like tag

var HelloComponent = function() {
   return (
    <h1 className="hello">
        <span>Hello World</span>
    </h1>
   )
};
  • The rendering into the html element with the root id.
ReactDOM.render(<HelloComponent/>, document.getElementById('root'));
<div id="root">
  <!-- Where react render the component -->
</div>
  • Result:

Node

When developing a React application in Node, you need to import it or require it.

var React = require ('React');

let message = 
    React.DOM.div(
		{
		className: 'hello',
		onClick: somFunc
		},
		[React.DOM.span(null, ['Hello World'])]
		);
	
React.renderComponent(message, document.body)		

Mapping React Class / HTML element

React Mapping Html Javascript

{this.props.text.toUppercase}

Model

Composition

React creates a DOM tree of React element that build a components hierarchy where:

or in the other direction

The root may represent:

Data / State

See React - State

Documentation / Reference