Allow not unwrapping refs when using store #2506
Replies: 3 comments 3 replies
-
For now, there is no intention of shipping this feature with the existing ones because it makes things different when using the store, while it is not explicit why things are not unwrapped anymore (still same That being said, I don't want to give up the idea yet completely, so I will move it to Discussions and see if the community comes up with other arguments |
Beta Was this translation helpful? Give feedback.
-
I have a similar issue, I have a store where I want to keep a document with thousands of lines. I would prefer to keep it is as a However Pinia just urefs all my references. My solution so far has been to return a computed prop which returns a global module refer shallowRef. However this breaks typescript types so it's not a great solution. Would be great to have a utility like |
Beta Was this translation helpful? Give feedback.
-
Pinia wraps the composing-store in a reactive, which causes all ComputedRef deconstructed from the store to lose reactivity.
|
Beta Was this translation helpful? Give feedback.
-
What problem is this solving
So when you use a store, it wraps it in a reactive, which is helpful since you don't have to use
.value
and it means composition and options stores are the same. But it's also really annoying because it's not what you expect it to be if you're returning refs and you can't destructure them. It's quite annoying to have to use storeToRefs or computed when it's not really necessary.Proposed solution
Solution 1: Allow passing an options object when you create the store, including the two current options, plus an option to not unwrap refs. This would be harder because wrapping it is done when you define it, at least that's what it looks like when I look at the source code.
Solution 2: Make this an option when you define the store instead of when you create it. This is easier, but it's probably not as good since it isn't obvious when you use it, you'd have to look at the definition or maybe the types.
Describe alternatives you've considered
No response
Beta Was this translation helpful? Give feedback.
All reactions