Last active
March 2, 2017 13:50
-
-
Save Ami777/b7e073ea6a32b605321cc6f9bc1cc160 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 from 'react'; | |
import ReactDOM from 'react-dom'; | |
document.addEventListener('DOMContentLoaded', function(){ | |
class ButtonToClick extends React.Component { | |
handleButtonClick = () => { | |
if ( typeof this.props.onClick === 'function' ){ | |
this.props.onClick(); | |
} | |
}; | |
render(){ | |
return <button onClick={this.handleButtonClick}>Click!</button>; | |
} | |
} | |
class ButtonCounter extends React.Component { | |
constructor(props){ | |
super(props); | |
this.state = { | |
count : 0, | |
}; | |
} | |
handleIncBtnClick = () => { | |
this.setState({ | |
count : this.state.count + 1 | |
}); | |
}; | |
render(){ | |
return <div> | |
<h1>{ this.state.count }</h1> | |
<ButtonToClick onClick={this.handleIncBtnClick}/> | |
<ButtonToClick onClick={this.handleIncBtnClick}/> | |
<ButtonToClick onClick={this.handleIncBtnClick}/> | |
<ButtonToClick onClick={this.handleIncBtnClick}/> | |
</div>; | |
} | |
} | |
class App extends React.Component { | |
render(){ | |
return <ButtonCounter />; | |
} | |
} | |
ReactDOM.render( | |
<App />, | |
document.getElementById('app') | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.