I have a following state declared
const [state, setState] = useState({
title: "",
subtitle: "",
products: [],
state.products
is an array of objects e.g.
products = [{a: "", b: "", c: ""}]
On form submit I want to take the input values and append them to the products array as an object.
My submit handler doesn't do what I want. Where have I gone wrong?
function handleSubmit(e) {
const newProduct= {"a": e.target[0].value, "b": e.target[2].value, "c": e.target[1].value}
setState({...state, products: [...state.products, newProduct]})
}