I'm in a bit of a pickle trying to reset my state with multiple reducers. I've come across various examples on how to reset the state of a Redux store. Here's one that caught my eye:
const appReducer = combineReducers({
/* your app’s top-level reducers */
})
const rootReducer = (state, action) => {
if (action.type === 'USER_LOGOUT') {
state = undefined
}
return appReducer(state, action)
}
My confusion lies in figuring out how to proceed. Specifically, how can I reset the state with the following setup:
This is how my rootReducer is structured:
export interface IState {
userReducer: IUserState;
sessionReducer: ISessionState;
authenticateReducer: IAuthenticateState;
articlesReducer: IArticlesState;
}
export const reducers = combineReducers<IState>({
userReducer,
sessionReducer,
authenticateReducer,
articlesReducer
});
Let me provide an example of the user state (IUserState) for better understanding, which is similar to the structure of other states:
export interface IUserState {
user: IUserEntity;
alert?: IAlertEntity;
errors: IErrorsEntity;
}
export const initialState: IUserState = {
errors: EmptyErrors(),
alert: EmptyMessage(),
user: EmptyUser()
};
So, how can I go about resetting my states and what would be the most efficient solution?