Skip to content

Instantly share code, notes, and snippets.

@codingnninja
Created September 5, 2018 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingnninja/db92f4f12e42ca87b3b23229b60b4389 to your computer and use it in GitHub Desktop.
Save codingnninja/db92f4f12e42ca87b3b23229b60b4389 to your computer and use it in GitHub Desktop.
class Vote extends React.Component {
constructor(){
super();
this.state = {
message: "Click on an image to vote"
};
this.voteForBuhari = this.voteForBuhari.bind(this);
this.voteForFela = this.voteForFela.bind(this);
this.voteForSowore = this.voteForSowore.bind(this);
}
voteForBuhari() {
this.setState({
message: "You just voted for Mohammadu Buhari"
});
}
voteForFela() {
this.setState({
message: "You just voted for Fela Durotoye"
});
}
voteForSowore() {
this.setState({
message: "You just voted for Sowore"
});
}
render() {
return (
<div>
<div class="row container center-block">
<h1>{this.state.message}!</h1>
<div class="col-sm-4">
<img
src="assets/images/buhari.jpg"
onClick={this.voteForBuhari}
/>
</div>
<div class="col-sm-4">
<img
src="assets/images/fela.jpg"
onClick={this.voteForFela}
/>
</div>
<div class="col-sm-4">
<img
src="assets/images/sowore.jpg"
onClick={this.voteForSowore}
/>
</div>
</div>
</div>
);
}
}
ReactDOM.render(
<Vote/>,
document.getElementById('root')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment