Last active
February 10, 2017 14:31
-
-
Save antonkartashov/a5cdf9527debd4f659246f9bf100ee26 to your computer and use it in GitHub Desktop.
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 Button extends Component { | |
static get defaultProps() { | |
return {color: 'red'} | |
} | |
handleClick() { | |
this.props.onClick() | |
} | |
render() { | |
return ( | |
<button className='Button' onClick={this.handleClick.bind(this)}> | |
Make {this.props.color} | |
</button> | |
) | |
} | |
} | |
class App extends Component { | |
constructor(props) { | |
super(props) | |
this.state = {color: 'ivory'} | |
} | |
changeColor(color) { | |
this.setState({color}) | |
} | |
render() { | |
return ( | |
<div className='App' style={{background: this.state.color}}> | |
<Button color='coral' onClick={this.changeColor.bind(this)} /> | |
<Button color='gold' onClick={this.changeColor.bind(this)} /> | |
<Button color='deepskyblue' onClick={this.changeColor.bind(this)} /> | |
</div> | |
) | |
} | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment