I don't know what might be wrong here, but i am following a tutorial and writing the same lines of code, but it seems that i am getting an error when i add this block of code.
setTeacherLoginData({
...teacherLoginData,
[event.target.name]:event.target.value
});
i am thinking that my error is related to this.
Since the value attribute is not updating, it's not possible to edit the given input field. You can solve this by adding an onChange event and the value attribute to the input field
this is the code i have written so far
const [ teacherLoginData, setTeacherLoginData ] = useState({
email: '',
password: '',
});
const handleChange = (event) => {
setTeacherLoginData({
...teacherLoginData,
[event.target.name]:event.target.value
});
};
const submitForm = () => {
console.log(teacherLoginData);
};
return (
<input value="{teacherLoginData.email}" onChange="{handleChange}" type="text" className="form-control" />
<input value="{teacherLoginData.password}" onChange="{handleChange}" type="password" className="form-control" />
<button onClick="{submitForm}" className="btn btn-primary">Login</button>
)
event.target.name, but it doesn't look like yourinputelements havenameattributes?