You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can't figure out a way to fetch data during static site generation and have it persist to the client side.
The fetching is happening inside of a composable that wraps useFetch and is widely used across the app.
Here's the ways I tried to migrate this composable:
useLazyAsyncData
This seemed like the most straight forward way of doing things, but the client first sees the page without the fetched data.
// This is the inside of a composable that receives url and returns stateconst{data: state}=useLazyAsyncData(url,()=>$http.$get(`${API_BASE}${url}`),{default: ()=>([]),transform: formatter})
useLazyAsyncData + onServerPrefetch
Then I tried to call the refresh function from useLazyAsyncData in onServerPrefetch. Still no initial data on client.
// This is the inside of a composable that receives url and returns stateconst{data: state, refresh}=useLazyAsyncData(url,()=>$http.$get(`${API_BASE}${url}`),{default: ()=>([]),transform: formatter})onServerPrefetch(async()=>{awaitrefresh()})
useState
An alternative way I tried is to have a useState ref and fetch data manually in onServerPrefetch. Still nothing.
// This is the inside of a composable that receives url and returns stateconststate=useState(url,()=>([]))onServerPrefetch(async()=>{constresponse=await$http.$get(`${API_BASE}${url}`)state.value=formatter(response)})
This is something I've been fighting with for a pretty long time now, so any advice would be appreciated!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I can't figure out a way to fetch data during static site generation and have it persist to the client side.
The fetching is happening inside of a composable that wraps
useFetch
and is widely used across the app.Here's the ways I tried to migrate this composable:
useLazyAsyncData
This seemed like the most straight forward way of doing things, but the client first sees the page without the fetched data.
useLazyAsyncData
+onServerPrefetch
Then I tried to call the
refresh
function fromuseLazyAsyncData
inonServerPrefetch
. Still no initial data on client.useState
An alternative way I tried is to have a
useState
ref and fetch data manually inonServerPrefetch
. Still nothing.This is something I've been fighting with for a pretty long time now, so any advice would be appreciated!
Beta Was this translation helpful? Give feedback.
All reactions