Skip to content

Instantly share code, notes, and snippets.

@xaviervia
Created February 1, 2017 15:16
Show Gist options
  • Save xaviervia/8ab16d67de111e12716bdd9bc4372fd6 to your computer and use it in GitHub Desktop.
Save xaviervia/8ab16d67de111e12716bdd9bc4372fd6 to your computer and use it in GitHub Desktop.
How we almost reinvent the Redux Store - II
class CustomCheckbox extends Component {
constructor () {
super()
this.state = {
checked: false
}
}
componentWillMount () {
if (this.props.autoChecked) {
this.setState({checked: true})
}
}
handleClick (...args) {
if (this.props.checked == null) {
this.setState({
checked: !this.state.checked
})
}
if (this.props.onClick) {
this.props.onClick(...args)
}
}
render () {
const checked = this.props.checked == null ? this.state.checked : this.props.checked
return <div onClick={this.handleClick}>
{checked ? 'Checked' : 'Not pressed'}
</div>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment