G
G
Gregory2019-07-18 11:49:22
React
Gregory, 2019-07-18 11:49:22

How to change the global redux store depending on the React App route?

Good afternoon. There is a large application consisting of two independent parts. One is loaded by default, the second is loaded when the "/bla-bla" route is appended. How can you make it so that when you go through this route, your redux store is loaded, which does not know anything about the existence of the default one?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-07-18
@Groyreg

In a good way, divide the application into two parts and define your own store in each.
But nothing prevents you from using an unlimited number of stores in one application:
Example 1:

const store1 = configureStore1();
const store2 = configureStore2();

const App = () => (
  <>
    <Provider store={store1}>
      <MainProject />
    </Provider>
    <Provider store={store2}>
      <SubProject />
    </Provider>
  </>
);

Example 2:
const store1 = configureStore1();
const store2 = configureStore2();

const App = () => (
  <Provider store={store1}>
    <>
      <MainProject />
      <Provider store={store2}>
        <SubProject />
      </Provider>
    </>
  </Provider>
);

With routing, the example will be a little more complicated, but the essence of this will not change.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question