以下代码是我在容器中调用这些函数的减速器的代码
const intialState = {
counter: 0,
results: []
};
const reducer = (state = intialState, action) => {
switch (action.type) {
case "INCREMENT":
return {
...state,
counter: state.counter + 1
};
case "STORE_RESULT": {
return {
...state,
results: state.results.push(state.counter)
};
}
}
return state;
};
export default reducer;
我收到以下错误
TypeError: state.results.push is not a function
reducer
1)我在我的项目中使用 redux reducer
2)我通过在我的容器中传递来自我的调度的类型来更新状态
3)我试图通过推送来更新数组(我知道它返回长度)但我想知道它为什么不起作用
4)下面的代码我在javascript中尝试过一切正常
var a = {
b:[]
}
a.b.push(11)
//output
1
吃鸡游戏
人到中年有点甜
哆啦的时光机
相关分类