Say I have the following array:
import {useState} from 'react';
const [products, setProducts] = useState([
{name: "Television", price: 1000},
{name: "Cellphone", price: 800},
{name: "Pen", price: 1}
])
and the following inputs and a button on another component:
<input placeholder="Name" value={} onChange={} />
<input placeholder="Price" value={} onChange={} />
<button onClick={insert function here}>Save</button>
How does one grab the new value from both inputs and add them as a new array to the original products array so that the result would be:
[
{name: "Television", price: 1000},
{name: "Cellphone", price: 800},
{name: "Pen", price: 1},
{name: "Chocolate", price: 5}
]
and not:
[
{name: "Television", price: 1000},
{name: "Cellphone", price: 800},
{name: "Pen", price: 1},
{name: "Chocolate"},
{price: 5},
]
Thank you!