1 回答

TA貢獻1804條經驗 獲得超8個贊
首先,請使用正確的映射。inventoryReducer 不是您要映射的那個。該對象內的庫存是您想要的。
const mapStateToProps = (reducers) => {
return reducers.inventoryReducer.inventory;
}
另外如果在 this.props.inventory 中獲取到數據,應該與重復鍵有關 請嘗試以下操作
printInventory = () => {
this.props.inventory.map((inventory, index) => {
return (
<CardInventario
key={index}
cardTitle={inventory.name}
quantity={inventory.quantity}
description={inventory.price}
/>
)
})
}
如果你沒有 id,可以使用索引代替(雖然不推薦)
printInventory = () => {
this.props.inventory.map((inventory) => {
return (
<CardInventario
key={inventory.id}
cardTitle={inventory.name}
quantity={inventory.quantity}
description={inventory.price}
/>
)
})
}
添加回答
舉報