I've a series of user data elements which I'm collecting inside a React component using hooks.
const [mobile, setMobile] = useState('');
const [username, setUsername] = useState('');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [confirmPassword, setConfirmPassword] = useState('');
Each of these are updated as follows.
<input type="text"
className="form-control"
id="mobile"
placeholder="Enter a valid mobile number"
onChange={event => {setMobile(event.target.value)}}/>
Is there a more succint way to do this using an object as the variable?
const [values, setValues] = useState({ mobile: "", ... });
. – GulledgeonChange
events. – WamsleysetValues({ ...values, [prop]: newValue });
? – Gulledge