Replacing redux toolkit store or other way to have two stores

Viewed 273

I have a following question. I was asked to make example project that compares Redux Toolkit Query and Redux Toolkit with use of Fetch API (or Axios).

I have the Redux Toolkit Query part. How can I add another store? Should I do:

<ChosenStoreContext>
  <Provider store={store}>
    <ApiProvider api={api}>
      ...Rest of the app
    </ApiProvider>
  </Provider>
</ChosenStoreContext>

with ChosenStoreContext (useContext boolean value) added just to tell components whether they should dispatch query actions or store actions

Or should I go completely other route? ApiProvider documentation says that it can cause conflicts. Any tips would be helpful!

1 Answers

An ApiProvider will also just create a store and use a Provider to pass that down - overwriting the original Provider.

Generally, you should have only one store in your application - and you can have both of those examples on different slices in one store, without them influencing each other.

There is an option of having mutiple different providers and sets of hooks using multiple contexts but that is extra work and will not gain you anything.

Just put everything in the same store.

Related