Created
March 30, 2016 12:25
-
-
Save xie-qianyue/b2755d24ddf543870cbd7413fd5a4159 to your computer and use it in GitHub Desktop.
React decorator function
This file contains 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 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