react-navigation
react-navigation copied to clipboard
redux integration causes circular dependency
I've implemented redux integration with the following reducer
export function navigation(state, action) {
return Navigator.router.getStateForAction(action, state)
}
where Navigator is
const Navigator = StackNavigator({
Main: {
screen: StacksInTabs,
},
}, {
mode: 'modal',
headerMode: 'none',
})
I'm trying to import my redux store within my application. However, since the StackNavigator depends upon every component in my app, importing my redux store creates a circular dependency.
This results in Navigator being undefined in the above reducer.
@gsaandy can you share what exactly you have done in this files
configureStore.ts
import { applyMiddleware, createStore, Middleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import defaultLogger from 'redux-logger';
import { persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import rootReducer from './reducers/rootReducer';
const { composeWithDevTools } = __DEV__ ? { composeWithDevTools: v => v } : require('redux-devtools-extension');
const middlewares: Middleware[] = [thunkMiddleware];
if (__DEV__) {
middlewares.push(defaultLogger);
}
const persistConfig = {
key: 'root',
storage,
whitelist: ['session', 'appConfig'],
};
const persistedReducer = persistReducer(persistConfig, rootReducer);
const createStoreWithMiddleware = composeWithDevTools(applyMiddleware(...middlewares))(createStore);
export default (initialState = {}) => createStoreWithMiddleware(persistedReducer, initialState);
storeRegistry.ts
import configureStore from './configureStore';
class StoreRegistry {
private storePersistor;
private store = configureStore();
getStore() {
return this.store;
}
registerStorePersistor(persistor) {
this.storePersistor = persistor;
}
getStorePersistor() {
return this.storePersistor;
}
}
export default new StoreRegistry();
