Created
December 1, 2016 14:21
-
-
Save oreqizer/56653caf2210be9fb827c9532c54a5af to your computer and use it in GitHub Desktop.
An example of a dumb component.
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
import React, { PropTypes, PureComponent } from 'react'; | |
import Todo from '../../../universal/containers/Todo'; | |
const doneStyle = { | |
textDecoration: 'line-through', | |
}; | |
const notDoneStyle = { | |
textDecoration: 'none', | |
}; | |
export default class TodoItem extends PureComponent { | |
static propTypes = { | |
todo: PropTypes.instanceOf(Todo).isRequired, | |
index: PropTypes.number.isRequired, | |
onEdit: PropTypes.func.isRequired, | |
onDelete: PropTypes.func.isRequired, | |
}; | |
constructor(props) { | |
super(props); | |
this.handleToggle = this.handleToggle.bind(this); | |
this.handleDelete = this.handleDelete.bind(this); | |
} | |
handleToggle() { | |
const { todo, index, onEdit } = this.props; | |
onEdit(todo.set('done', !todo.done), index); | |
} | |
handleDelete() { | |
const { todo, index, onDelete } = this.props; | |
onDelete(todo.id, index); | |
} | |
render() { | |
const { todo, index } = this.props; | |
return ( | |
<div | |
className="TodoItem" | |
style={todo.done ? doneStyle : notDoneStyle} | |
onClick={this.handleToggle} | |
> | |
<span className="TodoItem-text">{todo.text}</span> | |
<span className="TodoItem-delete-icon" onClick={this.handleDelete} /> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment