Answer the question
In order to leave comments, you need to log in
How to correctly update an object with values from different inputs?
const [user, setUser] = useState({})
const reg = (e) => {
const {name, value} = e.target
setUser(user[name] = value)
}
<input
name='name'
onChange={reg}
value={user.name} />
<input
name='surname'
onChange={reg}
value={user.surname} />
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question