Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created October 22, 2018 13:52
Show Gist options
  • Save prof3ssorSt3v3/0acefe82de524fdb4d13ccf6fd82d9be to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/0acefe82de524fdb4d13ccf6fd82d9be to your computer and use it in GitHub Desktop.
import React, {Component} from 'react';
export default class Person extends Component{
constructor(props){
super(props);
this.state={
hasChanged: false
}
}
increment = (ev) => {
ev.preventDefault();
this.setState({hasChanged:true});
this.props.increment(this.props.name);
}
render(){
return (
<div className="person">
<h2>{this.props.name}</h2>
<h3>{this.props.count}</h3>
<button onClick={this.increment}>Add</button>
{this.state.hasChanged && (
<span>Updated</span>
)}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment