Skip to content

Instantly share code, notes, and snippets.

@antonkartashov
Last active February 10, 2017 14:31
Show Gist options
  • Save antonkartashov/a5cdf9527debd4f659246f9bf100ee26 to your computer and use it in GitHub Desktop.
Save antonkartashov/a5cdf9527debd4f659246f9bf100ee26 to your computer and use it in GitHub Desktop.
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