Circular dependency of stores not working #2229
Unanswered
Thomas-1985
asked this question in
Help and Questions
Replies: 2 comments 1 reply
-
@Thomas-1985 Did you solve this? I have the same scenario but not the same error. Mine is : |
Beta Was this translation helpful? Give feedback.
1 reply
-
Have the same issue! Here's the fork of the the pinia todo app in the pinia-playground
Anyone figured it out? Cheers ✌️ |
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
-
We want to migrate from Vuex 3.5 to Pinia and have a problem with stores, which call each other.
We have a
rootStore
and annewStore
in Pinia.In an action of the
rootStore
, we try to useconst newStore = useNewStore();
Otherwise in an action of the the new store, we try to use
const rootStore = useRootStore();
This will not work, in the root store we get the error
TS2448: Block-scoped variable 'useNewStore' used before its declaration.
I guess this is because in the
defineStore
calls, each other function is called, creating a circular dependency.The pinia introduction says: "You can even have circular dependencies of stores"
Also we have read that this is possible here: https://pinia.vuejs.org/cookbook/composing-stores.html
But the example is using a
setup()
function for the stores, we use the same option structure as vuex (with data, getters, actions and so on) with the options api (with Vue 2.7)How can we solve this? Thanks for your help.
Beta Was this translation helpful? Give feedback.
All reactions