Computed does not work in nested store #2640
-
ReproductionSteps to reproduce the bug
Expected behaviormainStore.isNestedNumberOne is false Actual behaviormainStore.isNestedNumberOne is true Additional information
|
Beta Was this translation helpful? Give feedback.
Answered by
posva
Apr 9, 2024
Replies: 1 comment
-
The issue is about reactivity with Vue. By doing return {
nestedNumber: useNested().nestedNumber,
isNestedNumberOne: useNested().isNestedNumberOne,
mainNumber,
isMainNumberOne,
}; You are reading the numbers from Here is a fixed version of what you are trying to do but it duplicates the state in two stores, avoid doing that, use a computed to not duplicate the source of truth. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
posva
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The issue is about reactivity with Vue. By doing
You are reading the numbers from
nestedNumber
and the boolean fromisNestedNumberOne
. They are just values, not reactive wrappers (Ref), so they aren't reactive anymore: https://vuejs.org/guide/essentials/reactivity-fundamentals.html#limitations-of-reactiveHere is a fixed version of what you are trying to do but it duplicates the state in two stores, avoid doing that, use a computed to not duplicate the source of truth.