Seeking assistance with utilizing a root reducer to encapsulate my combined reducers for the purpose of resetting them upon a reset store action.
However, I am facing an issue where I cannot directly access the reducers using Store.getState().recuder1
There are no TypeScript errors as Store.getState()
is returning type any
. How can I determine the type of combinedReducers
in Store.getState()
after implementing rootReducer
?
Any help or guidance on this matter would be greatly appreciated.
const combinedReducers = combineReducers({
reducer1,
reducer2,
reducer3
});
const rootReducer = (state, action) : ReturnType<typeof reducer> => {
if (action.type === RESET_STORE) {
return combinedReducers(undefined, action)
}
return combinedReducers(state, action);
}
export default rootReducer;
This is how the store is configured:
declare global {
interface Window {
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?: typeof compose;
}
}
const composeEnhancer = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(rootReducer, composeEnhancer(applyMiddleware(thunk)));
export default store;
Prior to using the root reducer, I simply passed combinedReducers
to the store and could access all reducers through Store.getState().reducer1
/reducer2
, etc. This was beneficial during development as it allowed direct access to the reducers and their properties.