So im trying to create a form with functional components in React. I have a state which contains an object
const [event, setEvent] = useState(props.location.event);
{
"id": 1,
"limit": 2000,
"price": 10,
"accessLvl": 0,
"details": "Event that contains all the fields",
"duration": 24,
"eventType": 1,
"eventLocation": "asdasd",
"creator": 1,
"startDate": "2020-06-01T12:00:00",
"title": "Testing update",
"imageUrl": "d0659c5e-7ca1-4b02-b148-6221d6e7d7a8"
}
It is a edit form so i have the input values set to these variables. With class component i could do it easily but with functional component when i try to change one variable for example title and the object is only going to contain the title which is not the behavior that i want.
<input type="text" className="form-control" value={props.event.title} onChange={e => props.onTodoChange(e.target.value, "title")} id="EventTitle" />
function onTodoChange(value, key) {
setEvent({[key] : value})
}