New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useData
composable
#14924
Comments
This mean the data defined in |
(talking in context of full-static) With nuxt/framework#7567,
|
@pi0 great idea. but as I saw asyncData key are not allowed jet. Let’s say I have a compostable called „useCart“ with multiple functions „load“, „addItem“, „removeItem“ each of those functions includes an useasyncData call an return the same data (whole cart object). It’s it better to use watch the data in each functions and sync the data to a different state (useState(„currentCart“) or is it better the use the same key for asyncData and resolve as computed(()=> nuxt._asyncData[key])? |
@c-schwan If you building a global store pattern, I would advice using a combination of useAsyncData / useData are for the per-page state (while an example like useCart is a global state). |
@pi0 thx, but if i use the combination of useState and $fetch then i lose the useAsyncData functionality like { server: true | false}, lazy:true. So i have to duplicate the whole functionality fetching the data and store them |
Context: #14927, #14927
useState
is primarily to preserve initial state between client and server.useAsyncData
should be ideally used to store data but sometimes, it is more convenient to useuseState
and direct async logic to fill it. (usage in nuxt/content document-driven mode).We can introduce new
useData
composable that acts almost same asuseState
but is explicitly marked as page data and can be extracted to the static payloads.Alternatives:
useState
to always be extracted (like 3.0.0.rc.1) => It introduces network when it is really initial state and same between pagesuseState
to track changes => Not sure if possible at all for server but even if is, a custom async logic might initializes it before composable. It also makes implementation more complex internallyuseAsyncData
=> Seems not fitting for allThe text was updated successfully, but these errors were encountered: