The reaction is monitored against uncontrolled inputs.

I completed the React Form tutorial to create the component below:

export default class SignInForm extends React.Component { constructor(props) { super(props) this.state = { email: '', password: '' } this.onEmailChange = this.onEmailChange.bind(this) this.onPasswordChange = this.onPasswordChange.bind(this) } onEmailChange(event) { this.setState({email: event.target.value}) } onPasswordChange(password) { this.setState({password: event.target.value}) } render() { return ( <form onSubmit={this.props.handleSubmit}> <div> <label>Email</label> <div> <input type="email" placeholder=" you@gmail.com " onChange={this.onEmailChange} value={this.state.email} /> </div> </div> <div> <label>Password</label> <div> <input type="password" placeholder="Password" onChange={this.onPasswordChange} value={this.state.password} /> </div> </div> <button type="submit" class="btn btn-primary">Submit</button> </form> ) } } 

As soon as the form appears, I get the following error:

SignInForm changes the managed password input to an uncontrolled type. Input elements should not switch with uncontrolled (or vice versa). Solve using an uncontrolled input element for component lifetime

I cannot find a place where I make it an uncontrolled component. What am I doing wrong?

+6
source share
1 answer

It looks like your onPasswordChange method should be:

 onPasswordChange(event) { this.setState({password: event.target.value}) } 
+7
source

All Articles