In my react app, I have an array of objects data that gets render to the table. The data structure of the data that I have is in the following format:
this.state = {
inspectionViewAllRsData: [
{
INSPN_PERFORMER_CD: {label: "Contractor", value: "C"}
},
{
INSPN_RSN_CD: {label: "Initial", value: "INIT"}
},
{
INSPN_STS_CD: {label: "", value: "1000"}
}
]
}
and here's my code for the table:
<table>
<tr>
<th>Performed By</th>
<th>Inspection</th>
<th>Residence Size</th>
</tr>
{this.state.inspectionViewAllRsData.map((item, i) => (
<tr>
<td>{item.INSPN_PERFORMER_CD.label} <button id="close-btn" onClick={() => this.handleRemove(i)}>X</button></td>
<td>{item.INSPN_RSN_CD.label}</td>
<td>{item.RSDNC_SIZE_QTY.value}</td>
</tr>
))}
</table>
What I want to do is remove the selected index of an array from the state when I click on the "X" button. This is what I tried to do but it's giving me an error that row.filter is not a function
handleRemove = index => {
const newData = this.state.inspectionViewAllRsData.map(row => {
return row.filter((el, i) => i !== index);
});
console.log(newData)
this.setState({ inspectionViewAllRsData: newData });
}
Can someone please help me with my functionality? Any help would be appreciate it.