Differences between `computed` and a hook
See original GitHub issueWhat are the differences between using computed:
const model = {
user: null,
isLoggedIn: computed((state) => state.user !== null),
};
// In component
const isLoggedIn = useStoreState(state => state.model.isLoggedIn)
And a hook like this:
function useIsLoggedIn(){
const user = useStoreState(state => state.model.user)
return user !== null
}
// In component
const isLoggedIn = useIsLoggedIn()
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top Results From Across the Web
What is the Difference Between the Created and Mounted ...
The created() hook is used for fetching data from backend API and setting it to data properties. But in SSR, the mounted hook...
Read more >watch vs. watchEffect when to use what with Vue.js
The watchEffect() hook works like the computed() hook or the computed option, but instead of returning a value, you use it to trigger...
Read more >Computed Properties - Vue.js
Think of a computed property as declaratively describing how to derive a value based on other values - its only responsibility should be...
Read more >Methods, Computed, and Watchers in Vue.js | CSS-Tricks
In Vue, we use data to track changes to a particular property that we'd like to be reactive. Computed properties allow us to...
Read more >Vue JS - Differences between Computed and Watch
While computed properties are more appropriate in most cases, watchers are more powerful and allow us to perform complex operations such as HTTP ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Well it might be in some cases - and it all depends on your store. I would suggest you to test out if computed props are working in your case. If it works - great, if it doesn’t, you can get around it via the solution below.
Computed props are just derived of state. If you are worried that you might get cached computed props, you could extrapolate the “compute” generator and reuse it within your action/thunk to regenerate the data based on the current state.
The input is deep-diffed based on the previous previous input.
The computed property is also checked and only updated if it has changed, to prevent excessive renders.
see #764 for more details
State resolvers provides the input to the computed props. Equality checks are handled internally.
Read about state resolvers for computed props here.