我似乎无法重置默认状态;我怎么做?我试过这个,但它所做的只是添加state
来声明并将其称为undefined。如何将状态重置为初始状态?
const initialState = {
name: null,
coins: 0,
image: null,
};
export default function reducer(state = initialState, action = {}) {
switch (action.type) {
case types.ADD_GROUP_COINS:
return {
...state,
coins: state.coins + action.coins
};
case types.DELETE_GROUP:
return {
state: undefined
};
default:
return state;
}
}
'case types.DELETE_GROUP: return initialState;'不工作,或者那不是你想要的? – Aurora0001
那会给我'state:{state:{initialState}}'来代替。因为它将它分配给'state'在'state'里面' –
我不认为它会 - 'return {state:initialState}'会这样做 - 'return initialState'应该按预期工作。 – Aurora0001