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}
/>
)
})
}
添加回答
举报