Created
April 17, 2018 23:10
-
-
Save idmontie/217de99ff2e264cd0d18f123b2084f59 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
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