I have created a simple login form.
When I input the values and press the sign up button, the state values are shown in the console for a second and then they go away right after.
I was wondering why is the reason?
Here is the code:
class Login extends React.Component {
constructor(props){
super(props);
this.state = {
user: '',
pass:''};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(e){
const value = e.target.value;
this.setState({
[e.target.name]: value
})
}
handleSubmit(e){
console.log(this.state);
}
render() {
return (
<div>
<h1>Hello, {this.props.name}</h1>
this is a login <br/>
<form onSubmit={this.handleSubmit}>
<input type="text" name="user"
placeholder="user name"
onChange={e => this.handleChange(e)}
value={this.state.user}/> <br/>
<input type="text" name="pass"
placeholder="password"
onChange={e => this.handleChange(e)}
value={this.state.pass}/> <br/>
<button type="submit">Sign up</button>
</form>
</div>
)
}
};
export default Login