for @JSLuxembourg by Thierry Nicola / @littleiffel, Feb.2015
Address common challenges in Single-Page Web Applications with data that changes over time
“Lots of people use React as the V in MVC. Since React makes no assumptions about the rest of your technology stack, it's easy to try it out on a small feature in an existing project.”
var HelloMessage = React.createClass({
render: function() {
return Hello {this.props.name};
}
});
React uses a virtual DOM diff implementation for ultra-high performance. It can also render on the server using Node.js — no heavy browser DOM required.
React implements one-way reactive data flow which reduces boilerplate and is easier to reason about than traditional data binding.
var HelloMessage = React.createClass({
render: function() {
return Hello {this.props.name};
}
});
// Attach Component to DOM Node
React.render(<HelloWorld name='John' />, document.body);
var Timer = React.createClass({
getInitialState: function() {
return {secondsElapsed: this.props.init};
},
tick: function() {
this.setState({secondsElapsed: this.state.secondsElapsed + 1});
},
componentDidMount: function() {
this.interval = setInterval(this.tick, 1000);
},
componentWillUnmount: function() {
clearInterval(this.interval);
},
render: function() {
return (
Seconds Elapsed: {this.state.secondsElapsed}
);
}
});
React.render(<Timer init="100"/>, document.body);
var Form = React.createClass({
getInitialState: function() {
return {value: 'Hello!'};
},
handleChange: function(event) {
this.setState({value: event.target.value});
},
render: function() {
var value = this.state.value;
return ;
}
})
var Form = React.createClass({
render: function() {
return ;
}
})
Access via this.refs.myfield.getDOMNode().value
<html>
<head>
<script src="build/react.js"></script>
<script src="build/JSXTransformer.js"></script>
</head>
<body>
<div id="example"></div>
<script type="text/jsx">
var HelloMessage = React.createClass({
render: function() {
return Hello {this.props.name};
}
});
React.render(<HelloMessage name="John" />, document.getElementById('example'));
</script>
</body>
</html>
Flux is the application architecture that Facebook uses for building client-side web applications. It complements React's composable view components by utilizing a unidirectional data flow. It's more of a pattern rather than a formal framework
Thanks for your attention!