Passing arguments to useStore()? #826
-
I occasionally need to pass arguments to my stores but haven't been able to determine if it's possible in Pinia. Is it possible to do something like this, or a feature to consider? Or is this not a sensible thing to do? const selectedId = ref(0)
useStore(selectedId) // pass arguments defineStore('id', (selectedId) => {
const state = ref()
watch([state, selectedId], () => { ... })
return { state }
}) |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 16 replies
-
I usually add an action and calling upon creation because having it as an argument could be misleading as it's only used if the store created that time const store = useStore()
store.init(arguments) |
Beta Was this translation helpful? Give feedback.
-
I used this way.
export const useStore = defineStore({
const store = useStore().init(parameter); Don't know if this is the right way to use pinia. |
Beta Was this translation helpful? Give feedback.
-
Hello, is there a solution to this problem? I have the same problem now |
Beta Was this translation helpful? Give feedback.
-
My workaround for setup options. One storage for all ...
Dynamic storage = each components get its own
And more ES6 style
I really don't understand that it's not thought of from the beginning and it's nowhere in the documentation. |
Beta Was this translation helpful? Give feedback.
I usually add an action and calling upon creation because having it as an argument could be misleading as it's only used if the store created that time