How to get one store to react to changes in another? #1669
Unanswered
zachbryant
asked this question in
Help and Questions
Replies: 1 comment
-
This can be achieved in option stores by adding a |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have two stores, A and B. I want B to react to changes in A's state.
A has an action
fetchData
that completes as expected, and a getter/setter pairactiveObject
. User navigation dictatesactiveObject
. B has separate concerns but derives some state from A in its own getter,bFromA
.The docs on accessing another store's getter say you can "directly use it", but in practice this isn't working. My components that consume
bFromA
don't react to changes inactiveObject
based on the code below. If the hmr updates without a complete page reload, I do see the expected state change.it seems the only way to react to changes from A in B is to follow the action subscription approach and subscribe to
fetchData
. This seems completely counter to the docs, and what I think Pinia should be able to do without subscriptions. What's wrong with my approach?In reality, I have more stores than this. Merging A and B is not an option.
Store A
Store B
Component consuming B
Also Asked on SO
Beta Was this translation helpful? Give feedback.
All reactions