Skip to content

Instantly share code, notes, and snippets.

@coodoo
Created October 24, 2014 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coodoo/5c295d38250f4befa5e4 to your computer and use it in GitHub Desktop.
Save coodoo/5c295d38250f4befa5e4 to your computer and use it in GitHub Desktop.
Pre-render with react v.0.12
var React = require('react');
require('node-jsx').install();
var MyApp = React.createFactory( require('./myApp') );
var app = new MyApp({items:['a', 'b', 'c']});
var str = React.renderToString( app );
console.log( 'str: ', str, '\n\n\n', app );
/** @jsx React.DOM */
var React = require('react');
module.exports = React.createClass({
getInitialState: function() {
return {items: this.props.items}
},
handleClick: function() {
this.setState({items: this.state.items.concat(this.state.items.length)})
},
render: function() {
return <div>
<button onClick={this.handleClick} disabled={this.props.disabled}>Add Item</button>
<ul>
{this.state.items.map( function(item) {
return <li key={item}>{item}</li>
}
)}
</ul>
</div>
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment