I am trying to add a new row of input directly under the current row. However, I can only add the new input at the bottom of the array instead of directly after the object within the array
const initialState = [
{ name: "John", Age: 0, height: 0, weight: 0 },
{ name: "Mary", Age: 0, height: 0, weight: 0 },
{ name: "Darren", Age: 0, height: 0, weight: 0 },
{ name: "Eli", Age: 0, height: 0, weight: 0 },
];
const [infoValues, setInfoValues] = useState(initialState);
// I want to add the new row directly under the current one instead at the last
const addInputRow = () => {
setInfoValues([
...infoValues,
{ name: "Eli", Age: 0, height: 0, weight: 0},
]);
};
const removeInputRow = (index) => {
const valueList = [...infoValues];
valueList.splice(index, 1);
setInfoValues(valueList);
};
{ name: "Eli", Age: 0, height: 0, weight: 0}to appear in addition to theinitialStatearray. In other words, indicate what is the expected result based on your initial and input data.