Created
October 24, 2014 14:17
-
-
Save coodoo/5c295d38250f4befa5e4 to your computer and use it in GitHub Desktop.
Pre-render with react v.0.12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @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