Skip to content

Instantly share code, notes, and snippets.

@ihgrant
Forked from SuperManEver/model_react.jsx
Last active August 2, 2016 19:57
Show Gist options
  • Save ihgrant/7379f82efcafe5edeb675744a714c3e7 to your computer and use it in GitHub Desktop.
Save ihgrant/7379f82efcafe5edeb675744a714c3e7 to your computer and use it in GitHub Desktop.
adding model to react app
const React = require('react');
const ReactDOM = require('react-dom');
const TodoInput = require('./todo_input.js');
const TodoList = require('./todo_list.js');
var tasks = [
{ text : 'buy milk' },
{ text : 'do exercises' }
];
var _addTask = task => {
tasks.push(task);
render();
}
var App = React.createClass({
addTask : function(task) {
_addTask(task);
},
render : function() {
return <div>
<TodoInput addTask={this.addTask} />
<TodoList tasks={this.props.tasks} />
</div>;
}
});
function render () {
ReactDOM.render(<App tasks={tasks} />, document.getElementById('main'))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment