Skip to content

Instantly share code, notes, and snippets.

@BretCameron
Last active March 7, 2019 13:27
Show Gist options
  • Save BretCameron/c9147cc93b52bb24ec9aa8845004d78d to your computer and use it in GitHub Desktop.
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
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