Skip to content

Instantly share code, notes, and snippets.

@idmontie
Created April 17, 2018 23:10
Show Gist options
  • Save idmontie/217de99ff2e264cd0d18f123b2084f59 to your computer and use it in GitHub Desktop.
Save idmontie/217de99ff2e264cd0d18f123b2084f59 to your computer and use it in GitHub Desktop.
export default class Toggle extends Component {
state = { on: false }
onClick = (e) => {
e.preventDefault();
this.setState(state => ({
on: !state.on,
}));
}
render() {
const { on } = this.state;
return this.props.children({
on,
onToggle: this.onClick,
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment