Open dvvtms opened 7 years ago
same on V5
problem: components don't refreshing after rehydration, but the state changes. Components showing only initialState after dispatching action.
Resolved by adding handler to my rootReducer
, as in the example.
you can implement same on childReducers
for optimization, selecting correct reducer in action.payload
.
const appReducer = combineReducers({
nav: navReducer,
data: dataReducer,
services: servicesReducer,
// components: componentsReducer,
});
let nextState;
const rootReducer = (state, action) => {
switch (action.type) {
case action.type === 'SET_APP_RESET':
nextState = undefined;
return appReducer(nextState, action);
// added this
case action.type === REHYDRATE:
nextState = { ...state, ...action.payload };
return appReducer(nextState, action);
default:
return appReducer(nextState || state, action);
}
};```
hy guys. After Rehydration, i dispatch action, i get back the initialState, not the persisted state. Same result when i dispatch clean redux action or thunk
what i make wrong and how avoid that?