Created
August 16, 2017 13:52
-
-
Save palutz/fedbc317a6aae1db36ac4012ac8ff251 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
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
const green = '#39D1B4'; | |
const yellow = '#FFD712'; | |
class Toggle extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { color: green }; | |
this.changeColor = this.changeColor.bind(this); | |
} | |
changeColor() { | |
const newC = this.state.color == green ? yellow : green; | |
this.setState({ color : newC }); | |
} | |
render() { | |
return ( | |
<div style={{background: this.state.color}}> | |
<h1> | |
Change my color | |
</h1> | |
<button onClick={this.changeColor}> | |
Change color | |
</button> | |
</div> | |
); | |
} | |
} | |
ReactDOM.render( | |
<Toggle />, | |
document.getElementById('app') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment