I am new guy, a beginner one. I am trying to pass state but couldn’t do it. Below is my code, I want inputValue that is inside handleChange to be accessed in the handleSubmit. The text entered in the text box to be accessed in the handleSubmit which is triggered when submit is clicked. Any help would be more than appreciable.
class App extends Component {
constructor(props) {
super(props);
this.state = {
numOfClicks: 0,
};
this.handleClick = this.handleClick.bind(this);
this.handleChange = this.handleChange.bind(this);
this.handlecheckboxChange = this.handlecheckboxChange.bind(this);
}
handleClick = () => {
this.setState({numOfClicks: this.state.numOfClicks + 1});
};
handlecheckboxChange = (evt) => {
this.setState({genderValue: evt.target.value});
};
handleChange = (evt) => {
this.setState({inputValue: evt.target.value});
};
handleSubmit = (inputValue) => {
};
// handleSubmit(evt) {
// // this.setState({formData: data});
// console.log(handleChange.props.inputValue);
// }
render(){
return (
<div>
<p>
Enter Text<input type="text" value={this.state.inputValue} onChange={this.handleChange} />
</p>
<button onClick={this.handleClick}>Click Me!</button>
<p>Number of Times Clicked = {this.state.numOfClicks}</p>
<p>Entered Text = {this.state.inputValue}</p>
<div>
<p>Male<input name="gender" type="radio" value="male" onClick={this.handlecheckboxChange} /></p>
<p>FeMale<input name="gender" type="radio" value="female" onClick={this.handlecheckboxChange} /></p>
<p>Gender = {this.state.genderValue}</p>
</div>
<p><input type="submit" name="submit" onClick={this.handleSubmit} value="submit" /></p>
<p>Form Data = {this.state.formData}</p>
</div>
)
}
}
export default App;