Я хочу удалить детали из моей таблицы. Я не звоню в API. Это все из магазина редуксов.
Это мой редуктор. js:
case billsTypes.DELETE_DETAIL:{
const id = action.payload.data._id
return{
...state,
details: state.bill.detail.filter(item => item._id !== id)
}
}
Это мое действие. js
export const deleteDetail = id => dispatch =>{
dispatch({type: billsTypes.DELETE_DETAIL, payload: id});
};
И это рендеринг, когда я выполняю действие:
render(){
const{detailItem,index,fields,isSubtotal} = this.props;
return(
<tr key={index}>
<td>
<Field
id={`${detailItem}._id`}
name={`${detailItem}.quantity`}
type='number'
component= {UtilityQuantity}
placeholder= '...quantity'
// label = "Quantity"
/>
</td>
<td>
<Field
id={`${detailItem}._id`}
name={`${detailItem}.product.code`}
type="number"
component= {UtilityCode}
placeholder='...Product's code'
//label = "Product's code"
/>
</td>
<td>
<Field
id={`${detailItem}._id`}
name={`${detailItem}.product.name`}
type="text"
component= {UtilityName}
placeholder='...Product's name'
// label = "Product's name"
/>
</td>
<td>
<Field
id={`${detailItem}._id`}
name={`${detailItem}.product.price`}
type="number"
component= {UtilityPrice}
placeholder= '...Price'
// label = "Product's price"
/>
</td>
<td>
<Field
id={`${detailItem}._id`}
name={`${detailItem}.subtotal`}
component= {UtilitySubtotal}
placeholder= '...subtotal'
// label = "Subtotal"
>
{isSubtotal}
</Field>
</td>
<td>
{/* <button className='btn btn-light mr-2'
type="button"
title="Remove Detail"
onClick={() => fields.remove(index)}>
Delete
</button> */}
<a
className='mr-2'
href='#more'
onClick={() => {
if (
window.confirm(
'Are you sure to want to delete the item?'
)
)
this.props.deleteDetail(detailItem._id);
}}
>
DELETE ITEM
</a>
</td>
</tr>
);
}
}
Когда я нажимаю на УДАЛИТЬ ПУНКТ, у меня появляется эта ошибка:
TypeError: Невозможно прочитать свойство 'data' из неопределенного
В этих строках кода:
case billsTypes.DELETE_DETAIL:{
const id = action.payload.data._id
return{
...state,
details: state.bill.detail.filter(item => item._id !== id)
}
}
Я не вызываю api rest, потому что я работаю из онлайн-хранилища.
Как я могу исправить эту ошибку ?, Мне нужно решить это, но я не знаю, могу ли это сделать.