Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] LOCATION_CHANGE called on each new reducer injected in store #119

Open
remitestut opened this issue Oct 8, 2023 · 0 comments
Open

Comments

@remitestut
Copy link

Hello,

I'm trying to replace connected-react-router by your library.
I'm using react-router-dom v6.
Everything looks fine but I got a problem when injecting new reducer in my store.
On each new reducer injected, LOCATION_CHANGE action is called.
I didn't have this issue with connected-react-router and react-router-dom v5.

Here is my code to reproduce the problem :

const {
    createReduxHistory,
    routerMiddleware,
    routerReducer
} = createReduxHistoryContext({ history: createBrowserHistory() });

const reducers = {
    ...staticReducers,
    router: routerReducer,
}

const createReducer = (staticReducers, addeddReducers) => combineReducers({ ...staticReducers, ...addeddReducers });

const store = configureStore({
    reducer: reducers,
    middleware: getDefaultMiddleware => {
        return getDefaultMiddleware({
            immutableCheck: false,
            serializableCheck: false,
        })
            .concat(routerMiddleware)
    },
});

store.asyncReducers = {};
store.injectReducer = (key, reducer) => {
    store.asyncReducers[key] = reducer;
    store.replaceReducer(createReducer(reducers, store.asyncReducers));
}

const history = createReduxHistory(store);

store.injectReducer("reducerToAdd", reducerToAdd);

const bootApplication = async () => {
    const appRoot = createRoot(document.getElementById("root"));

    appRoot.render(
        <ReduxProvider store={store}>
            <HistoryRouter history={history}>
                NOTHING TO SEE
                <Link to={"another/route"}>TEST</Link>
            </HistoryRouter>
        </ReduxProvider>
    );
};

bootApplication();

Did I forgot something ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant