I am trying to input data from a form like this -
<h1>Company Position</h1>
<input
name="company.position"
type="text"
onChange={(e) => functions.setData(e)}
value={data.company.position}
/>
Into a state Object like this -
const [ form, setValues ] = useState({
name : 'Jo Smith',
email : 'JoSmith@domain.com',
phone : null,
company : {
name : null,
position : null
}
});
Using a handleStateChange function where I pass in the target
const handleStateChange = (e) => {
e.preventDefault();
setValues({
...form,
[e.target.name]: e.target.value
});
};
I cant seem to update the company object inside state I assumed that it would recognize company.name as the target name.
Any help would be appreciated.