Skip to content

Instantly share code, notes, and snippets.

@sarahsweat
Last active March 27, 2019 16:29
Show Gist options
  • Save sarahsweat/38c358a19763e8191a02bd6c99655966 to your computer and use it in GitHub Desktop.
Save sarahsweat/38c358a19763e8191a02bd6c99655966 to your computer and use it in GitHub Desktop.
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