Created
October 1, 2018 20:42
-
-
Save buckatech/4d16ec7d778c49c6e0254eb5fd0d231a 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
const React = require('react'); | |
const ReactDOM = require('react-dom'); | |
const PropTypes = require('prop-types') | |
require('./index.css'); | |
const root = document.getElementById("root"); | |
class ChangeColors extends React.Component { | |
constructor() { | |
super(); | |
this.state = { color: "black" }; | |
} | |
handleClick() { | |
this.setState(state => ({ | |
colorIs: !state.isToggleOn | |
})); | |
} | |
render() { | |
const redButton = () => { | |
this.setState({ color: "red" }); | |
}; | |
const blueButton = () => { | |
this.setState({ color: "blue" }); | |
}; | |
const greenButton = () => { | |
this.setState({ color: "green" }); | |
}; | |
const style = { color: this.state.color }; | |
return ( | |
<div> | |
<h1 style={style}>Change My Colour!</h1> | |
<p> | |
<button onClick={redButton}> | |
Red | |
</button> | |
<button onClick={blueButton}> | |
Blue | |
</button> | |
<button onClick={greenButton}> | |
Green | |
</button> | |
</p> | |
</div> | |
); | |
} | |
} | |
ReactDOM.render(<ChangeColors />, root); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment