add useTRPCAsyncData composable

This commit is contained in:
Robert Soriano
2022-05-18 21:40:33 -07:00
parent b9d3a4942c
commit d28895cf5e
9 changed files with 129 additions and 52 deletions

View File

@@ -21,7 +21,7 @@ export default defineNuxtConfig({
trpcURL: '/api/trpc', // defaults to /api/trpc
},
typescript: {
strict: true // set this to true to infer input/output types
strict: true // set this to true to make input/output types work
}
})
```
@@ -64,6 +64,22 @@ console.log(farewell); // => 👈 goodbye
</script>
```
## `useTRPCAsyncData`
A composable that wraps Nuxt's [`useAsyncData`](https://v3.nuxtjs.org/api/composables/use-async-data/) with some modifications to have better error handlings.
```ts
const path = 'hello'
const client = useClient()
const {
data,
pending,
error,
refresh
} = await useTRPCAsyncData(path, () => client.query(path))
```
## Recipes
- [Validation](/recipes/validation.md)