moving from Nuxt2 useFetch to Nuxt3 useAsyncData - how would you refactor this example?
Hello, as a title says, how would you refactor this example to keep SSR working exactly 1:1?
Nuxt 2
Nuxt 2
const homePage = ref<HomePage | null>(null)
const homePageLoaded = ref<boolean>(false)
useFetch(async () => {
homePage.value = await loadHomePage()
homePageLoaded.value = true
})useState for this is a good way... could you please help/explain, how to refactor it with the smallest amount of other code changes possible?const { data, status } = await useFetch()PENDING?data (or status or similar) would be betterconst homePageLoaded = ref(false);
const homePage = ref(1);
async function loaddata(){
const{ data: thedata } = useAsyncData( async () => {
return await loadHomePage();
});
homePage.value=thedata;
homePageLoaded.value = true;
}
await loaddata();watch(() => watachablevalue, (newVal,oldVal) => {
//use variable or do something when variable changes.
}); 
transform? or doing that in asyncData after the fetching the call from an API?refresh which comes from the useAsyncData and return the whole composable "response object" insteadexecute and refresh the same functionallity? const homePageLoaded = ref<boolean>(false)
const { data: homePage } = useAsyncData(async () => {
homePage.value = await loadHomePage()
homePageLoaded.value = true
return homePage
}) const { data: homePage, pending: homePageLoaded } = useAsyncData(async () => {
return await loadHomePage()
})const { data, status } = await useFetch()PENDINGconst homePageLoaded = ref(false);
const homePage = ref(1);
async function loaddata(){
const{ data: thedata } = useAsyncData( async () => {
return await loadHomePage();
});
homePage.value=thedata;
homePageLoaded.value = true;
}
await loaddata();watch(() => watachablevalue, (newVal,oldVal) => {
//use variable or do something when variable changes.
});refreshrefreshconst { data, pending, error, refresh } = await useFetch('/api/auth/login', {
onRequest({ request, options }) {
// Set the request headers
options.headers = options.headers || {}
options.headers.authorization = '...'
},
onRequestError({ request, options, error }) {
// Handle the request errors
},
onResponse({ request, response, options }) {
// Process the response data
localStorage.setItem('token', response._data.token)
},
onResponseError({ request, response, options }) {
// Handle the response errors
}
})export const useHomePage = async () => {
const onSuccess = new SimpleEventDispatcher()
const onError = new SimpleEventDispatcher()
const {data, execute} = useAsyncData(async () => {
try {
const response = await doSomething()
onSuccess.dispatch(response)
return response
} catch (e) {
onError.dispatch(e)
}
}, {immediate: false})
await execute()
return {
onSuccess,
onError,
data,
execute
}
}