Skip to content

Instantly share code, notes, and snippets.

@makarovas
Created July 7, 2018 13:45
Show Gist options
  • Save makarovas/24b0f03b6a2729ca2e097d6bc3fd9729 to your computer and use it in GitHub Desktop.
Save makarovas/24b0f03b6a2729ca2e097d6bc3fd9729 to your computer and use it in GitHub Desktop.
<div id="root">
</div>
.box {
display: block;
width: 200px;
height: 200px;
background-color: gray;
color: white;
text-align: center;
vertical-align: middle;
cursor: pointer;
}
.box.green {
background-color: green;
}
class App extends React.Component {
constructor(props) {
super(props);
this.state = {addClass: false}
}
toggle() {
this.setState({addClass: !this.state.addClass});
}
render() {
let boxClass = ["box"];
if(this.state.addClass) {
boxClass.push('green');
}
return(
<div className={boxClass.join(' ')} onClick={this.toggle.bind(this)}>{this.state.addClass ? "Remove a class" : "Add a class (click the box)"}<br />Read the tutorial <a href="http://www.automationfuel.com" target="_blank">here</a>.</div>
);
}
}
ReactDOM.render(<App />, document.getElementById("root"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment