【发布时间】:2021-08-09 15:56:18
【问题描述】:
我想在 redux 中存储一个对象,但它给出了错误--->
未处理的拒绝(错误):对象作为 React 子对象无效(发现:对象带有键 {coord, weather, base, main, visibility, wind, clouds, dt, sys, timezone, id, name, cod} )。如果您打算渲染一组子项,请改用数组。
它正在保存数据但它不呈现它显示上述错误。 你能帮我保存这个对象吗?
代码
dispatch(weather(data)); //storing the object
//action
export const weather = (t) =>{
return({
type: 'Change',
payload: t,
});
}
//reducers
const weather = (state = null, action) => {
switch (action.type) {
case "Change_weather":
return state = action.payload;
default:
return state;
}
}
export default weather;
【问题讨论】:
-
你能分享你的代码吗?
-
@iskandar47,共享
标签: reactjs react-native redux react-redux