我不知道我试图从 mongo 映射对象数组的组件发生了什么,但是它没有向 printInventory 显示任何内容,但是如果我调用 this.props.inventory 并且它需要所有数据!怎么了?
printInventory = () => {
this.props.inventory.map((inventory) => {
return (
<CardInventario
cardTitle={inventory.name}
quantity={inventory.quantity}
description={inventory.price}
/>
)
})
}
在这些功能中。
接下来我将展示动作和减速器:
inventoryReducer:
import {TAKE_INVENTORY} from '../../types/inventoryTypes';
const INITIAL_STATE ={
inventory: []
}
function invetoryReducer(state = INITIAL_STATE,action){
switch (action.type) {
case TAKE_INVENTORY:
return {...state, inventory: action.payload}
break;
default:
return state;
break;
}
}
export default invetoryReducer;
这是 inventoryActions:
import axios from 'axios'
import { TAKE_INVENTORY } from '../../types/inventoryTypes'
export const takeInventory = () => async (dispatch) =>{
const res = await axios.get('http://localhost:3001/inventory')
dispatch({
type: TAKE_INVENTORY,
payload: res.data
})
}
胡说叔叔
相关分类