Espen @
Made by
Forget it.
Same concern,
different technology.
Read: build step "required"
render: function() {
return React.createElement("div", {className: "mything"},
React.createElement("a", {href: "/path"},
"Link: ", this.props.linkText
)
);
}
render: function() {
return (
<div className="my-thing">
<a href="/path">
Link: {this.props.linkText}
</a>
</div>
);
}
DOM-names,
not HTML-names
Render on every change!
wow
amaze
var EventListItem = React.createClass({
render: function() {
var e = this.props.event;
return (
<li>
<div className={'icon icon-' + e.type} />
<div className="minute">{e.minute}</div>
<div className="text">{e.text}</div>
</li>
);
}
});
var EventList = React.createClass({
render: function() {
var events = this.props.events;
if (this.props.match.isFinished) {
events = events.reverse();
}
return (
<ul className="event-list">
{events.map(EventListItem)}
</ul>
);
}
});
Virtual DOM
<li>
<div class="icon icon-yellowcard"></div>
<div class="minute">30</div>
<div class="text">Yellow card: BIRGER HANSEN.</div>
</li>
<li>
<div class="icon icon-redcard"></div>
<div class="minute">30</div>
<div class="text">Red card: BIRGER HANSEN.</div>
</li>
vs
=
li.children[0].className = 'icon icon-redcard';
li.children[2].innerText = 'Red card: BIRGER HANSEN.';
FAST
FAST
react-canvas
react-gibbon
React Native
var SongTitle = React.createClass({
propTypes: {
artist: React.PropTypes.string,
song: React.PropTypes.string.isRequired
},
render: function() {
return (
<span className="song-title">
<span className="artist-name">
{this.props.artist}
</span> -
<span className="song-name">
{this.props.song}
<∕span>
</span>
);
}
});
class SongTitle extends React.Component {
render() {
return (
<span className="song-title">
<span className="artist-name">
{this.props.artist}
</span> -
<span className="song-name">
{this.props.song}
<∕span>
</span>
);
}
}
SongTitle.propTypes = {
artist: React.PropTypes.string,
song: React.PropTypes.string.isRequired
}
Triggers re-render of component.
Espen
Hovlandsdal