Quick UI
without worries
by Maksim Kozhukh
Typical problems
of web apps
Backbone
Angular
Ember
...
or won't ...
Model View Controller
var HelloWorld = React.createClass({
render: function(){
return React.DOM.p("Hello world");
}
});
React.renderComponent(
HelloWorld(),
document.getElementById('example')
);
We've just learned 30% of react.js
return React.DOM.ul([
React.DOM.li("Option A"),
React.DOM.li("Option B")
])
return "<ul><li>Option A</li><li>Option B</li></ul>";
Virtual DOM
Sounds crazy, but it works faster :)
Typical problems
of web apps
var HelloWorld = React.createClass({
render: function(){
return React.DOM.p( "Hello world " + this.props.index );
}
});
var HelloUniverse = React.createClass({
render: function() {
var worlds = [];
for(var i=0; i<100; i++)
worlds.push( HelloWord({ index: i }));
return React.DOM.div(worlds);
}
});
The level of learning react.js is 50%
var HelloWorld = React.createClass({
render: function(){
return React.DOM.p( "Hello world " + this.props.index );
}
});
var HelloUniverse = React.createClass({
render: function() {
var worlds = [];
for(var i=0; i<100; i++)
worlds.push( HelloWord({ index: i }));
return React.DOM.div(worlds);
}
});
/** @jsx React.DOM */
var HelloWorld = React.createClass({
render: function(){
return <p>Hello world {this.prop.index}</p>;
}
});
var HelloUniverse = React.createClass({
render: function() {
var worlds = [];
for(var i=0; i<100; i++)
worlds.push( <HelloWorld index={i} /> );
return <div>(worlds)</div>;
}
});
The most difficult example
var HelloUniverse = React.createClass({
getInitialState:function(){
return { start: 0; }
},
shiftNext:function(){
this.setState({ start : this.state.start + 1 });
},
render: function() {
var worlds = [];
var start = this.start.state;
for(var i=start; i<start + 10000; i++)
worlds.push( <HelloWorld index={i} onClick={this.onClick} /> );
return <div onClick={this.shiftNext}>(worlds)</div>;
}
});
The most difficult example - State
var HelloUniverse = React.createClass({
getInitialState:function(){
return { start: 0; }
},
shiftNext:function(){
this.setState({ start : this.state.start + 1 });
},
render: function() {
var worlds = [];
var start = this.start.state;
The most difficult example
render: function() {
var worlds = [];
var start = this.start.state;
for(var i=start; i<start + 10000; i++)
worlds.push( <HelloWorld index={i} onClick={this.onClick} /> );
return <div onClick={this.shiftNext}>(worlds)</div>;
}
});
Typical problems
of web apps