Accessing store from another store
See original GitHub issueIs it possible to access a store from another store?
Or is this an anti-pattern?
Is store composition the way to go?
Or do you just access the raw state like such:
// Getting non-reactive fresh state
const paws = useBearStore.getState().paws
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Accessing store from another store · Issue #44 · pmndrs/zustand
I'm making this use-case up, so it might be unrealistic. Or would it be better to force components to compose stores together like...
Read more >Accessing the Store | React Redux
Accessing the Store. React Redux provides APIs that allow your components to dispatch actions and subscribe to data updates from the store.
Read more >Access Stores from Other Stores - A Vue.js Lesson From our ...
In this lesson, we learn how to access a Pinia store from another Pinia store. Thankfully, with Pinia the process is quite intuitive...
Read more >Access the Redux Store Outside a React Component
If you need to dispatch actions from outside a React component, the same technique will work: import the store, then call store. dispatch()...
Read more >How to access store state from a different store module in vuex?
Actions take a context object as parameter, you can use it to access rootState. Check documentation for other available options.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I had been wondering it too, but just recently got the idea to relate with flux/redux.
We should model the store like this:
those are store slices.
This is an idiomatic way in zustand, but zustand itself is unopinionated and using multiple stores is totally fine.
The primary use case is a single store. Multiple stores make sense if they are totally isolated. It sounds like for your use case, a single store would be a good pattern.