Skip to content

Instantly share code, notes, and snippets.

@palutz
Created August 16, 2017 13:52
Show Gist options
  • Save palutz/fedbc317a6aae1db36ac4012ac8ff251 to your computer and use it in GitHub Desktop.
Save palutz/fedbc317a6aae1db36ac4012ac8ff251 to your computer and use it in GitHub Desktop.
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