Created
February 1, 2017 15:16
-
-
Save xaviervia/8ab16d67de111e12716bdd9bc4372fd6 to your computer and use it in GitHub Desktop.
How we almost reinvent the Redux Store - II
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
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