|
@ -1,40 +1,41 @@ |
|
|
var TODO_COMPONENT = "\ |
|
|
var TODO_COMPONENT = ` |
|
|
var TodoList = React.createClass({\n\ |
|
|
var TodoList = React.createClass({ |
|
|
render: function() {\n\ |
|
|
render: function() { |
|
|
var createItem = function(itemText) {\n\ |
|
|
var createItem = function(itemText) { |
|
|
return <li>{itemText}</li>;\n\ |
|
|
return <li>{itemText}</li>; |
|
|
};\n\ |
|
|
}; |
|
|
return <ul>{this.props.items.map(createItem)}</ul>;\n\ |
|
|
return <ul>{this.props.items.map(createItem)}</ul>; |
|
|
}\n\ |
|
|
} |
|
|
});\n\ |
|
|
}); |
|
|
var TodoApp = React.createClass({\n\ |
|
|
var TodoApp = React.createClass({ |
|
|
getInitialState: function() {\n\ |
|
|
getInitialState: function() { |
|
|
return {items: [], text: ''};\n\ |
|
|
return {items: [], text: ''}; |
|
|
},\n\ |
|
|
}, |
|
|
onChange: function(e) {\n\ |
|
|
onChange: function(e) { |
|
|
this.setState({text: e.target.value});\n\ |
|
|
this.setState({text: e.target.value}); |
|
|
},\n\ |
|
|
}, |
|
|
handleSubmit: function(e) {\n\ |
|
|
handleSubmit: function(e) { |
|
|
e.preventDefault();\n\ |
|
|
e.preventDefault(); |
|
|
var nextItems = this.state.items.concat([this.state.text]);\n\ |
|
|
var nextItems = this.state.items.concat([this.state.text]); |
|
|
var nextText = '';\n\ |
|
|
var nextText = ''; |
|
|
this.setState({items: nextItems, text: nextText});\n\ |
|
|
this.setState({items: nextItems, text: nextText}); |
|
|
},\n\ |
|
|
}, |
|
|
render: function() {\n\ |
|
|
render: function() { |
|
|
return (\n\ |
|
|
return ( |
|
|
<div>\n\ |
|
|
<div> |
|
|
<h3>TODO</h3>\n\ |
|
|
<h3>TODO</h3> |
|
|
<TodoList items={this.state.items} />\n\ |
|
|
<TodoList items={this.state.items} /> |
|
|
<form onSubmit={this.handleSubmit}>\n\ |
|
|
<form onSubmit={this.handleSubmit}> |
|
|
<input onChange={this.onChange} value={this.state.text} />\n\ |
|
|
<input onChange={this.onChange} value={this.state.text} /> |
|
|
<button>{'Add #' + (this.state.items.length + 1)}</button>\n\ |
|
|
<button>{'Add #' + (this.state.items.length + 1)}</button> |
|
|
</form>\n\ |
|
|
</form> |
|
|
</div>\n\ |
|
|
</div> |
|
|
);\n\ |
|
|
); |
|
|
}\n\ |
|
|
} |
|
|
});\n\ |
|
|
}); |
|
|
React.render(<TodoApp />, mountNode);\ |
|
|
|
|
|
"; |
|
|
React.render(<TodoApp />, mountNode); |
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
React.render( |
|
|
React.render( |
|
|
<ReactPlayground codeText={TODO_COMPONENT} />, |
|
|
<ReactPlayground codeText={TODO_COMPONENT} />, |
|
|