Created
July 7, 2018 13:45
-
-
Save makarovas/24b0f03b6a2729ca2e097d6bc3fd9729 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
<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