【发布时间】:2016-02-18 09:14:38
【问题描述】:
我很难弄清楚这一点,基本上我正在尝试将状态设置为初始状态,到目前为止我尝试过:
// -- Initial state ------------------------------------------------------------
const INITIAL_STATE = {
search: {
listings: []
},
listings: []
}
// -- Story structure for story editor -----------------------------------------
export default function(state = INITIAL_STATE, action) {
switch(action.type) {
case ACTIONS.RESET_STATE:
return { ...state, INITIAL_STATE }
default:
return state;
}
}
这只是将初始状态添加到现有状态
case ACTIONS.RESET_STATE:
return { ...state, state = INITIAL_STATE }
这会返回错误
case ACTIONS.RESET_STATE:
return { ...state, state: INITIAL_STATE }
这是将初始状态添加到现有的增益中
case ACTIONS.RESET_STATE:
return { ...state, search: { listings:[] }, listings: [] }
这可行,但我开始遇到奇怪的突变错误。
【问题讨论】:
标签: javascript state redux