Skip to content

Instantly share code, notes, and snippets.

@xie-qianyue
Created March 30, 2016 12:25
Show Gist options
  • Save xie-qianyue/b2755d24ddf543870cbd7413fd5a4159 to your computer and use it in GitHub Desktop.
Save xie-qianyue/b2755d24ddf543870cbd7413fd5a4159 to your computer and use it in GitHub Desktop.
React decorator function
function BaseTodoItem(props) {
return {
render() {
return (
<label>{props.content}</label>
)
}
}
}
function MakeCompletable(Child) {
class Completable extends Component {
render() {
const {checked, onChange, ...childProps} = this.props;
return (
<div>
<input
className = "toggle"
type = "checkbox"
checked = {checked}
onChange = {onChange} />
<Child {...childProps} />
</div>
)
}
}
return Completable;
}
function MakeDeletable(Child) {
class Deletable extends Component {
render() {
const {onDelete, ...otherProps} = this.props;
return (
<div>
<Child {...otherProps} />
<button
className = "delete-todo"
onClick = {onDelete} />
</div>
);
}
}
return Deletable;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment