Last active
December 12, 2016 10:32
-
-
Save rricard/cd111be1f5796a50c15cd08b2754e965 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function Todo({todo, onToggle}) { | |
return ( | |
<li> | |
<input | |
type="checkbox" | |
onClick={onToggle} | |
checked={todo.done} | |
/> | |
{todo.done ? | |
<span style={{textDecoration: 'line-through'}}>{todo.title}</span> : | |
todo.title} | |
</li> | |
); | |
} | |
class TodoApplication extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
todos: [ | |
{title: 'Write a TODO app without React', done: true}, | |
{title: 'Write the rest of the article', done: false}, | |
], | |
}; | |
} | |
render() { | |
return ( | |
<ul> | |
{this.state.todos.map((todo, key) => ( | |
<Todo | |
todo={todo} | |
key={key} | |
onToggle={() => this.setState({ | |
todos: this.state.todos.map((t, i) => i === key ? {...t, done: !t.done} : t) | |
})} | |
/> | |
))} | |
</ul> | |
); | |
} | |
} | |
ReactDOM.render(<TodoApplication />, document.getElementById('app')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment