docs: improve docs

This commit is contained in:
wobsoriano
2022-12-18 23:25:46 -08:00
parent 09e0a6c479
commit f01b8d5d8d
10 changed files with 211 additions and 56 deletions

View File

@@ -1,5 +1,5 @@
---
title: Simple Usage
title: Simple
description: tRPC-Nuxt provides first class integration with tRPC.
---
@@ -77,10 +77,8 @@ export default createNuxtApiHandler({
Create a strongly-typed plugin using your API's type signature.
```ts [plugins/client.ts]
import { httpBatchLink } from '@trpc/client'
import { createTRPCNuxtClient } from 'trpc-nuxt/client'
import { createTRPCNuxtClient, httpBatchLink } from 'trpc-nuxt/client'
import type { AppRouter } from '~/server/trpc/routers'
import { FetchError } from 'ofetch'
export default defineNuxtPlugin(() => {
/**
@@ -91,30 +89,6 @@ export default defineNuxtPlugin(() => {
links: [
httpBatchLink({
url: '/api/trpc',
/**
* Replace regular `fetch` with a `$fetch` from nuxt
*
* During server-side rendering, calling $fetch to fetch your internal API routes
* will directly call the relevant function (emulating the request),
* saving an additional API call.
*
* @see https://nuxt.com/docs/api/utils/dollarfetch
*/
fetch: (input, options) =>
globalThis.$fetch.raw(input.toString(), options)
.catch((e) => {
if (e instanceof FetchError && e.response)
return e.response
throw e
})
.then(response => ({
...response,
json: () => Promise.resolve(response._data),
})),
}),
],
})

View File

@@ -1,5 +1,5 @@
---
title: Recommended Usage
title: Recommended
description: tRPC-Nuxt provides first class integration with tRPC.
---
@@ -112,10 +112,8 @@ If you need to split your router into several subrouters, you can implement them
Create a strongly-typed plugin using your API's type signature.
```ts [plugins/client.ts]
import { httpBatchLink } from '@trpc/client'
import { createTRPCNuxtClient } from 'trpc-nuxt/client'
import { createTRPCNuxtClient, httpBatchLink } from 'trpc-nuxt/client'
import type { AppRouter } from '~/server/trpc/routers'
import { FetchError } from 'ofetch'
export default defineNuxtPlugin(() => {
/**
@@ -126,30 +124,6 @@ export default defineNuxtPlugin(() => {
links: [
httpBatchLink({
url: '/api/trpc',
/**
* Replace regular `fetch` with a `$fetch` from nuxt
*
* During server-side rendering, calling $fetch to fetch your internal API routes
* will directly call the relevant function (emulating the request),
* saving an additional API call.
*
* @see https://nuxt.com/docs/api/utils/dollarfetch
*/
fetch: (input, options) =>
globalThis.$fetch.raw(input.toString(), options)
.catch((e) => {
if (e instanceof FetchError && e.response)
return e.response
throw e
})
.then(response => ({
...response,
json: () => Promise.resolve(response._data),
})),
}),
],
})