Thursday, February 08, 2018

Addition of Two value using ReactJS

First the user enter the value in the number1 and number2 are the textfield and we had written onChange event on this text field
onChange={(event)=>this.setState({number1:event.target.value})}
onChange={(event)=>this.setState({number2:event.target.value})}
Second the user click on the button and code onClick={this.doAction} is executed.
doAction()
{
this.setState({result : parseInt(this.state.number1) + parseInt(this.state.number2) });
}
Note: Before using any variable we have to declare it inside constructor. We also need to register the action method using this object



No comments: