Last active
March 27, 2019 16:29
-
-
Save sarahsweat/38c358a19763e8191a02bd6c99655966 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import React from 'react' | |
import styled from 'styled-components' | |
export default class BasicToggler 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> | |
<div> | |
<button onClick={this.toggle}>Click to toggle</button> | |
<p>This is toggled {isToggled ? 'ON' : 'OFF'}</p> | |
</div> | |
</HomeWrapper> | |
) | |
} | |
} | |
const HomeWrapper = styled.div` | |
height: 200px; | |
width: 400px; | |
text-align: center; | |
background-color: yellow; | |
` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment