Are separate stores created with defineStore merged together? #1622
Replies: 2 comments
-
I couldn't replicate the problem in an isolated example. The problem must be in the application that I'm working with. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Maybe you are pushing the same object (its reference instead of a copy) to both arrays and thus seeing it update in both arrays when you modify one: const obj = { n: 0 }
one.array.push(obj)
two.array.push(obj)
// instead do
one.array.push({ ...obj }) |
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.
-
Hello,
This is my first time using Pinia and I couldn't find an explanation for what I'm seeing in the documentation 1. Please forgive me if this is an obvious aspect of the library and allow me to explain the problem that I'm facing.
It looks like the state held inside Pinia stores with different IDs is merged together and causing components to see the same data despite them using different stores. This happens for data returned by the
state
function that share the same key. Please see the example code below 2.My question is: are stores defined with
defineStore
merged together into one global store? If so, is there any way to keep them separate without having to give state variables unique names?Thanks for your help and advice.
Footnotes
I've read all docs on the official Pinia website. I've also searched this repository's issues and discussions for "conflict", "global store", "merge", "same name", "state" and couldn't find any relevant information. ↩
<FirstComponent>
and<SecondComponent>
live on different pages switched by Vue Router. ↩Beta Was this translation helpful? Give feedback.
All reactions