Why am I unable to type into my form with the following code? I've correctly set my form values to the data in the state but I'm unable to type into them.
Component is changing an uncontrolled input of type email to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component.
construtor()
{
super(props);
this.state= { user: {} }
this.onChange = this.onChange.bind(this);
}
componentWillReceiveProps(nextProps)
{
this.state.user !== nextProps.user &&
this.setState({ user: nextProps.user });
}
onChange(e)
{
let newUser = this.state.user;
newUser[e.target.name] = e.target.value;
this.setState({ user: newUser });
}
<form>
<input name="email" type="email" className="form-control" value={this.state.user.email} onChange={this.onChange}/>
<input name="first_name" type="text" className="form-control" value={this.state.user.first_name} onChange={this.onChange}/>
</form>