This is my App
import React, { useState } from "react";
import Input from "./components/Input";
function App() {
const [newRow, setNewRow] = useState([]);
const addRow = (event) => {
event.preventDefault();
setNewRow(
newRow.concat(<Input key={newRow.length} myKey={newRow.length} />)
);
};
return (
<div>
<button onClick={addRow}>Add row</button>
<ul>
<Input key={newRow.length} myKey={newRow.length}/>
{newRow}
</ul>
</div>
);
}
export default App;
And this is my Input component
import "./Input.css";
import React, { useState } from "react";
const Input = (props) => {
const [updatedList, setUpdatedList] = useState([])
const deleteRow = (event) => {
event.preventDefault();
const key = props.myKey;
setUpdatedList(updatedList.splice(key, 1));
console.log(updatedList);
};
const disableRow = (event) => {
event.preventDefault();
};
return (
<li className="item">
<select>
<option value="+">+</option>
<option value="-">-</option>
</select>
<input type="text" />
<button onClick={deleteRow}>Delete</button>
<button onClick={disableRow}>Disable</button>
</li>
);
};
export default Input;
I guess I'm supposed to delete and disable the List HTML element through its key but I'm getting an empty array when I console.log(updatedList). So how can I delete from the original array in the parent component from the child component?