@samselikoff
Modeling state over time is the hardest part of GUIs
Difficult to remember end state after series of dynamic changes
Old server-side model doesn't have this problem
Ideally, just describe how your component looks at any time based on its state, and "refresh" whenever data changes
With React, we get this
Separation of templates and component code is artificial
Not really embracing web standards
hate the DOM
don't think web components are a really good way to build UIsĀ
Rendering server-side vs shipping an app to the browser
Philosophical differences
var Timer = React.createClass({
getInitialState: function() {
return {secondsElapsed: 0};
},
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 (
<div>Seconds Elapsed: {this.state.secondsElapsed}</div>
);
}
});
React.render(<Timer />, mountNode);
`render` returns a description of what it wants its UI to look like
Not actual DOM nodes, but lightweight descriptors. "Create an H3 and and div please". Virtual DOM
React manages the actual DOM nodes for you
uniform interface: initial + update are both in render
No DOM manipulation in our react class
we're only concerned with what to render, now how to render it
Components doesn't care about the current state of the DOM