question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`useData` composable

See original GitHub issue

Context: https://github.com/nuxt/framework/issues/7562, https://github.com/nuxt/framework/issues/7562

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 use useState and direct async logic to fill it. (usage in nuxt/content document-driven mode).

We can introduce new useData composable that acts almost same as useState 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 pages
  • useState 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 internally
  • useAsyncData => Seems not fitting for all

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pi0commented, Sep 15, 2022

(talking in context of full-static)

With #7567, useState will not be cleared on nav

useData is same as useAsyncData only not having an async fetcher and can be replaced for current implementation in nuxt/content of useState. Content modules shall use useData with keys specific to each page for state that is variant to each page. This way it won’t be overridden but cached on CSR nav.

0reactions
c-schwancommented, Sep 16, 2022

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Already Composable
Use data orchestration to execute a multi-head strategy and gain synergy. Not all platforms are truly composable.
Read more >
Jetpack Compose: How to handle states inside a ...
state is used to locally mutate and use data within the composition context. We'll focus on state function for our topic. Remember function ......
Read more >
10 things you need to know before implementing ...
Composable analytics is the term used to describe the ability to assemble analytical models by combining data and operations from multiple sources.
Read more >
Composables | Vue Storefront 2 for Magento
Usage. Let's see how you can use the useUser composable to load the current user's data: <script> ...
Read more >
The Emergence of the Composable Customer Data Platform
... with having to use data engineering tools that are native to the CDP, ... Composable CDP with Snowplow, Databricks, and Hightouch ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found