I have done this before in a react project.
const [formState, setFormState] = useState({ username: '', password: '', });
const handleInputChange = (e)=>{
if(e.target.name==="username"){
setFormState({...formState, username:e.target.value })
}
if(e.target.name==="password"){
setFormState({...formState, password:e.target.value })
}
}
My two input elements had the onChange={handleInputChange} to update input value.
Now I have a form that has numerous inputs. And I want a code that can update the input based on the input name. something like this.
const handleInputChange=(e)=>{
const inputName = e.target.name;
const value = e.target.value;
setFormState({...formState, inputName:value })
};
I need help on that please