Skip to content

Instantly share code, notes, and snippets.

@sarahsweat
Last active March 27, 2019 16:27
Show Gist options
  • Save sarahsweat/6ab05d521ec53dcc863e1090c208f58e to your computer and use it in GitHub Desktop.
Save sarahsweat/6ab05d521ec53dcc863e1090c208f58e to your computer and use it in GitHub Desktop.
export default class Toggler extends React.Component {
state = {
isToggled: false
}
toggle = () => {
this.setState(state => ({isToggled: !state.isToggled}))
}
render() {
const { isToggled } = this.state
return(
<HomeWrapper>
<h1> This is my Main Component </h1>
<ToggleWindow toggle={this.toggle} isToggled={isToggled} />
</HomeWrapper>
)
}
}
const ToggleWindow = ({toggle, isToggled}) => (
<div>
<button onClick={toggle}>Click to toggle</button>
<p>This is toggled {isToggled ? 'ON' : 'OFF'}</p>
</div>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment