I am trying to create a form which has two inputs and a button. When you click the button, the input fields are used to update the state and then show an alert with the information saved in the state. Currently, I have the inputs changing the state but its calling the alert function every time a letter is added to the input...
handleSubmit= (e) =>{
alert(JSON.stringify(this.state, null, ' '));
}
render() {
return (
<div className="App">
<label>
Username:
<input
type="text"
name="username"
placeholder="username"
value={this.state.username}
onChange={e => this.setState({ username: e.target.value })}
/>
</label>
<label>
Password:
<input
type="text"
name="password"
placeholder="password"
value={this.state.password}
onChange={e => this.setState({ password: e.target.value })}
/>
</label>
<button onClick={this.handleSubmit()}>Submit</button>
<p>{this.state.token}</p>
<WelcomeStory></WelcomeStory>
</div>
);
};
Thank you, this is my first front end framework so it has been a big learning curve.