Last active
March 27, 2019 16:27
-
-
Save sarahsweat/6ab05d521ec53dcc863e1090c208f58e 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 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