question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How to implement multiple stores with redux-toolkit?

See original GitHub issue

I’m working on a micro-front-ends architecture app, where one shell app will render multiple remote apps under single roof. I want to have an mf as a centralized redux store to which all the remote apps can connect to share common state. And remote apps should also have their own redux stores for their local states…

Here’s the issue… if central store and local store both have a state called count, updating this state in any of the stores, updates both of them, they behave as if it’s the exact same state.

I tried changing the store names… like centralStore and localStore, it didn’t have any effect. I tried changing the slice name… then the nearest store worked and the other store stopped working…

in the following example, localStore works… and the centralStore stops working.

function CentralStoreProvider({children}) {
    return <Provider store={centralStore}>{children}<Provider />
}

// app.js
<CentralStoreProvider>
    <Provider store={localStore}>
        <App />
    <Provider />
<CentralStoreProvider>

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
phryneascommented, Dec 14, 2022

Generally, you can have multiple stores with different contexts and different hooks. This is described in custom context. But if you can avoid it, avoid id.

0reactions
SurjitSahoocommented, Dec 19, 2022

Generally, you can have multiple stores with different contexts and different hooks. This is described in custom context. But if you can avoid it, avoid id.

Thanks… It solved my issue…

Basically, I want to have a way to share some common states across mf apps, without having any side-efect on those apps, if they need something, they can just import it from central-store… they don’t even need to know is it redux or something else.

Thanks again …

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Redux - multiple stores, why not? - Stack Overflow
As with several other questions, it is possible to create multiple distinct Redux stores in a page, but the intended pattern is to...
Read more >
Redux FAQ: Store Setup
As with several other questions, it is possible to create multiple distinct Redux stores in a page, but the intended pattern is to...
Read more >
Handling multiple stores in a React-Redux application
In a react-redux application, it is a good practice to have only one redux store. But if for some weird/“special” reason if you...
Read more >
Multiple Stores with React-Redux v6 - CodeSandbox
Implementing multiple stores using (multiple) custom context. 3. 20.5k.
Read more >
Handling multiple stores with redux toolkit in react.js - Medium
In my to-do app, Plan Your Day, I wanted to handle two data stores, one with logging-in data, and another with data inside...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found