Created
April 17, 2018 23:46
-
-
Save idmontie/f3342526d4313d611fb06d101b3ff030 to your computer and use it in GitHub Desktop.
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
class App extends Component { | |
state = { clickCount: 0 } | |
canClick() { | |
return this.state.clickCount < 4; | |
} | |
onIncrement() { | |
this.setState(state => ({ | |
clickCount: state.clickCount + 1, | |
})); | |
} | |
render() { | |
return ( | |
<Toggle> | |
{({ on, onToggle }) => ( | |
<Fragment> | |
<Switch on={on} onToggle={(e) => { | |
if (!this.canClick()) return; | |
this.onIncrement(!on ? 1 : 0); | |
onToggle(e); | |
}} /> | |
</Fragment> | |
)} | |
</Toggle> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment