Skip to content

Computed does not work in nested store #2640

Closed Answered by posva
p0wl90 asked this question in Help and Questions
Discussion options

You must be logged in to vote

The issue is about reactivity with Vue. By doing

return {
    nestedNumber: useNested().nestedNumber,
    isNestedNumberOne: useNested().isNestedNumberOne,
    mainNumber,
    isMainNumberOne,
  };

You are reading the numbers from nestedNumber and the boolean from isNestedNumberOne. They are just values, not reactive wrappers (Ref), so they aren't reactive anymore: https://vuejs.org/guide/essentials/reactivity-fundamentals.html#limitations-of-reactive

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.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by posva
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2639 on April 05, 2024 12:50.