Skip to content

Instantly share code, notes, and snippets.

@idmontie
Created April 17, 2018 23:46
Show Gist options
  • Save idmontie/f3342526d4313d611fb06d101b3ff030 to your computer and use it in GitHub Desktop.
Save idmontie/f3342526d4313d611fb06d101b3ff030 to your computer and use it in GitHub Desktop.
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