Today I was just trying to create a form for login/signup with functional components and useState hook with React. However, I ran into this issue. If anyone can help, it would be greatly appreciated. I tried searching for a reason, however, it was to no avail. Thanks.
- As soon as I provide input into the email field, I receive a warning. ''Warning: A component is changing a controlled input of type undefined to be uncontrolled. Input elements should not switch from controlled to uncontrolled (or vice versa). '' I do not know where my code is going wrong for this.
function Login(){
const [state, setState] = useState({
email:'',
password:'',
})
const handleChange = e => {
setState({ [e.target.name]: e.target.value })
}
const handleSubmit = e => {
e.preventDefault();
var email = state.email;
var password = state.password;
// Firebase requires passwords to be of length 6 or above
if (password.length < 6) {
alert("Password must of length 6 or more.");
} else {
fire.auth().createUserWithEmailAndPassword(email, password);
alert("Signed Up Successfully!");
}
}
return(
<>
<Navbar/>
<div>
<form>
<input name="email" value={state.email} onChange={handleChange} placeholder="email"></input>
<input name="password" value={state.password} onChange={handleChange} placeholder="password"></input>
<button type="submit" onClick={handleSubmit}>Sign Up!</button>
<button type="submit">Login!</button>
</form>
</div>
</>
);
}