I'm fetching some data from a JSON file. I'm using the map method to display it and it's stored in a state. I need to be able to delete an item when the delete button is clicked. I'm using the filter method to filter out that specific item but I get this error: Uncaught TypeError: Cannot read properties of undefined (reading 'filter')
export default function Customers() {
const { appData, setAppData } = useContext(AppContext);
const { customers, packages } = appData;
function handleDeleteCustomer(id) {
console.log(id)
setAppData(setAppData.customers.filter(customer => customer.id !== id), appData.packages)
}
return (
<TableContainer component={Paper}>
<Table sx={{ minWidth: 650 }} aria-label="simple table">
<TableHead>
<TableRow>
<TableCell >id</TableCell>
<TableCell >Name</TableCell>
<TableCell />
<TableCell />
</TableRow>
</TableHead>
<TableBody>
{appData.customers.map((row) => {
return (
<TableRow sx={{ '&:last-child td, &:last-child th': { border: 0 } }}>
<TableCell component="th" scope="row">{row.id}</TableCell>
<TableCell >{row.name}</TableCell>
<TableCell ><Button variant="contained">Create Invoice</Button></TableCell>
<TableCell ><Button variant="contained" onClick={() => handleDeleteCustomer(row.id)}>Delete</Button></TableCell>
</TableRow>
)
})}
</TableBody>
</Table>
</TableContainer>
)
}