Last active
March 7, 2019 13:27
-
-
Save BretCameron/c9147cc93b52bb24ec9aa8845004d78d to your computer and use it in GitHub Desktop.
The final file of the React.js tutorial, which switches between 'day' and 'night' modes
This file contains hidden or 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, { Component } from 'react'; | |
import './App.css'; | |
class App extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { skin: 'night' }; | |
this.changeSkin = this.changeSkin.bind(this); | |
} | |
changeSkin() { | |
const newState = this.state; | |
this.state.skin === 'night' ? newState.skin = 'day' : newState.skin = 'night'; | |
this.setState(newState); | |
} | |
render() { | |
return ( | |
<div className={this.state.skin}> | |
<header className="App-header"> | |
<p onClick={this.changeSkin} style={{ fontSize: '50px', cursor: 'pointer' }}>Change Skin</p> | |
</header> | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment