Skip to content

Instantly share code, notes, and snippets.

@MeliAlbu
Created August 25, 2020 00:40
Show Gist options
  • Save MeliAlbu/275b252f46b4b702c67c0785cfa96319 to your computer and use it in GitHub Desktop.
Save MeliAlbu/275b252f46b4b702c67c0785cfa96319 to your computer and use it in GitHub Desktop.
class Sum extends Component {
constructor(props) {
super(props);
this.state = {
firstValue: "",
secondValue: "",
sumVar: "",
};
}
handleFirstInput(e) {
this.setState({
firstValue: e.target.value,
});
}
handleSecondInput(e) {
this.setState({
secondValue: e.target.value,
});
}
handleClick() {
var number1 = this.state.firstValue;
var number2 = this.state.secondValue;
var Sum = parseInt(number1) + parseInt(number2);
this.setState({ sumVar: Sum });
}
render() {
return (
<div>
<input type="text" onChange={(e) => this.handleFirstInput(e)} />
<input type="text" onChange={(e) => this.handleSecondInput(e)} />
<button onClick={() => this.handleClick()}>Sumar</button>
<p>La suma es {this.state.sumVar}</p>
</div>
);
}
}
export default Sum;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment