N
Nuxt9mo ago
ægteemil

`useAsyncState` equivalent in Nuxt

Hey. Up until now I've been using useAsyncState from VueUse when doing any CRUD work through a service of mine, and I'm curious if this is bad practice and if there's an equivalent function baked into Nuxt? Today I'm doing something like this, which I'm looking to translate similarly to a Nuxt composable of some sort:
const { isLoading, execute: createApiKey } = useAsyncState(async (name: string) => {
await CustomersService.create({ name: name });
}, null, {
immediate: false,
onError: (error) => {
useApiErrorToast(error);
}
});
const { isLoading, execute: createApiKey } = useAsyncState(async (name: string) => {
await CustomersService.create({ name: name });
}, null, {
immediate: false,
onError: (error) => {
useApiErrorToast(error);
}
});
2 Replies
Likonima
Likonima9mo ago
afaik as i understand this function (also read here https://antfu.me/posts/async-with-composition-api) this is meant to be for non blocking logic on page load. in your case a simple function is enough, as you do an asynchronous operation anyways (non blocking)
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server