I have two mapped lists of items. When I click on the div using onClick={(e) => handleCheckClick(ele)} I want to display the clicked items in a table but I am getting errors.
handleCheckClick function
function handleCheckClick(ele) {
if (trayItems?.length > 0) {
settrayItems(
trayItems.map((item) => {
return { ...item, quantity: item.quantity + 1 };
})
);
} else {
settrayItems([...trayItems, ele]);
}
}
How I map two list items into div
<div>
{
item && item.filter((person) => person.status == "0").map((ele) => {
return (
<div
className="newmo-card"
style={styles.innerbox}
onClick={(e) => handleCheckClick(ele)}>
{`${ele.item}`}
<br />
<span> {`${ele.total_price}`}</span>
</div>
);
})
}
</div>
<Tray trayItems2={trayItems} trayItems1={trayPrice} />
Table of clicked items:
function Tray({ trayItems }) {
return (
<>
<div className="foo">
<table>
{trayItems &&
trayItems.map((ele, index) => {
return (
<tr key={index}>
<td>{ele.item}</td>
<td>{ele.price}</td>
<td>{ele.quantity}</td>
</tr>
</table>
</div>
</>
);
}
Check the sandbox so you can identify the issue