Hello there 👋
First of, thanks for a nice package! 🤝
I have a situation where I would like to mix regular state properties and properties returned by this package within a nested object. What I would like is this:
somePropertyAtTheFirstLevelOfTheState: "...",
computed: {
somePropertyThatIsARegularStateProperty: "...",
somePropertyThatIsComputedByZustandComputed: "..."
}
Some of my computed properties are based on other store states, so I have subscriptions that update the state when needed. Conceptually they are all computed so of course I want to have them at the same place.
I've realized that if I create my computed state like this it will not merge the properties within computed but replace the whole object:
const computed = createComputed((state) => ({
computed: { somePropertyThatIsComputedByZustandComputed: state.someThing * 2 }
}))
However I can simply spread computed to make it work:
const computed = createComputed((state) => ({
computed: {
...state.computed,
somePropertyThatIsComputedByZustandComputed: state.someThing * 2
}
}))
This feels a bit weird though and so my question is simply if this is a bad idea or not? I'm thinking e.g that there might create a dependency to state.computed and cause a loop? ♻
Hello there 👋
First of, thanks for a nice package! 🤝
I have a situation where I would like to mix regular state properties and properties returned by this package within a nested object. What I would like is this:
Some of my computed properties are based on other store states, so I have subscriptions that update the state when needed. Conceptually they are all computed so of course I want to have them at the same place.
I've realized that if I create my computed state like this it will not merge the properties within
computedbut replace the whole object:However I can simply spread
computedto make it work:This feels a bit weird though and so my question is simply if this is a bad idea or not? I'm thinking e.g that there might create a dependency to
state.computedand cause a loop? ♻