Reputation: 3968
I have the following code:
constructor(props) {
super(props);
this.state = {
search: "",
value: "",
username:'',
email:'',
password: '',
};
this.onChange = this.onChange.bind(this);
this.onSubmit = this.onSubmit.bind(this);
}
...
...
onChange(e) {
this.setState(
{[e.target.name]: e.target.value})
}
...
...
<input type="password" placeholder="Password"
onChange={e => this.onChange(e)}
value={ this.state.password }
/>
But I can't type into the password field.
If I remove the value={ this.state.password }
part I can then type into the field, but it seems like my state isn't being updated when this field is changed.
What is the problem?
Upvotes: 2
Views: 105
Reputation: 644
Or rather U can have ur onChange like this:
onChange(e) {
this.setState(
{password: e.target.value})
}
Upvotes: 0
Reputation: 1015
You forgot to give name to the password field. It should be
<input
type="password"
placeholder="Password"
name="password"
onChange={e => this.onChange(e)}
value={ this.state.password }
/>
Upvotes: 5