当我更新 redux 状态时,它给出错误 TypeError: object is not iterable (cannot read property Symbol(Symbol.iterator))
const initialState = {
articles: []
};
function rootReducer(state = initialState, action) {
switch(action.type){
case ADD_ARTICLE:{return [...state,action.payload];} # error occurs in this line
default:return state;
}
}
export default rootReducer;
最佳答案
您正在尝试克隆 {}
而非 []
的状态。尝试按以下方式返回:
switch(action.type) {
case ADD_ARTICLE: {
return {
...state,
action.payload
};
}
default: {
return ...state;
}
}
关于javascript - React JS,Redux状态更新错误,无法读取属性Symbol(Symbol.iterator),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61911489/