0
我正在使用redux來保持視圖的狀態,因此當用戶回來時他們具有與之前選擇的視圖和設置完全相同的視圖和設置,我這樣做會將事件發送到服務器並複製這些更改在後端的商店中並將狀態存儲在數據庫上。在初始化時檢查redux狀態的完整性
每次在我們用戶登錄獲得使用該CIDE他設置:
if(!user.state){
socket.store = redux.createStore(reducer);
}else{
socket.store = redux.createStore(reducer, user.state);
}
的問題出現時,我想添加新功能和狀態保存在數據庫中新的減速變得過時,我嘗試通過老態對象到createStore功能我得到
[Error: Reducer "fooReducer" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may n
ot be undefined.
我的減速器:
//this is a new reducer
function fooReducer(state, action) {
if (!state) {
state = defaultState.foo
}
switch (action.type) {
...
default:
return state
}
}
module.exports = combineReducers({
theme: themeReducer,
settings: settingsReducer,
foo: fooReducer,
});
減速機不應檢查未定義狀態是否涵蓋這些情況? 當我想添加新的減速器時,處理這種情況和未來情況的最佳做法是什麼?
我想編寫一個函數來檢查的狀態每個鍵被初始化,但這看起來像是減速應該已經做