设置数据:
export const setIngredients = (ingredients) => {return { type: actionTypes.SET_INGREDIENTS,ingredients : ingredients}}
获取数据:
export const initIngredients = () => {return dispatch => {axios.get('....').then(response => {dispatch(setIngredients(response.data));}).catch( error => {dispatch(fetchIngredientsFailed())})} }
错误:
Objects are not valid as a React child (found: object with keys {objectId, name, createdAt, updatedAt, value}). If you meant to render a collection of children, use an array instead.
return dispatch => { axios.get('......').then(response => {dispatch(setIngredients(response.data)
);{dispatch(fetchIngredientsFailed())}
1条答案
按热度按时间6qqygrtg1#
这似乎不是你的API获取Axios代码的问题,而是渲染逻辑的问题。
在JSX代码中的某个地方,您直接引用了
ingredients
的对象/数组,这就是它给出此错误的原因。因为react不支持对象或数组作为子组件。您也可以参考此问题,Objects are not valid as a React child. If you meant to render a collection of children, use an array instead