Skip to content

Commit

Permalink
docs: fix tabs in readme [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalbalaji committed Aug 3, 2024
1 parent 1de6539 commit fa0223b
Showing 1 changed file with 48 additions and 48 deletions.
96 changes: 48 additions & 48 deletions @lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ The following instructions assume the `tRPC` router to have the following proced

```typescript
export const router = t.router({
greeting: t.procedure
.input((name: unknown) => {
if (typeof name === 'string') return name;

throw new Error(`Invalid input: ${typeof name}`);
})
.query(async ({ input }) => {
return `Hello, ${input} from tRPC v10 @ ${new Date().toLocaleTimeString()}`;
}),
greeting: t.procedure
.input((name: unknown) => {
if (typeof name === 'string') return name;

throw new Error(`Invalid input: ${typeof name}`);
})
.query(async ({ input }) => {
return `Hello, ${input} from tRPC v10 @ ${new Date().toLocaleTimeString()}`;
}),
});

export type Router = typeof router;
Expand All @@ -81,12 +81,12 @@ import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
import { svelteQueryWrapper } from 'trpc-svelte-query-adapter';

const client = createTRPCProxyClient<Router>({
links: [
httpBatchLink({
// Replace this URL with that of your tRPC server
url: 'http://localhost:5000/api/v1/trpc/',
}),
],
links: [
httpBatchLink({
// Replace this URL with that of your tRPC server
url: 'http://localhost:5000/api/v1/trpc/',
}),
],
});

export const trpc = svelteQueryWrapper<Router>({ client });
Expand Down Expand Up @@ -122,19 +122,19 @@ Here is an example of what that might look like:
import type { QueryClient } from '@tanstack/svelte-query';

const client = createTRPCProxyClient<Router>({
links: [
httpBatchLink({
// Replace this URL with that of your tRPC server
url: 'http://localhost:5000/api/v1/trpc/',
}),
],
links: [
httpBatchLink({
// Replace this URL with that of your tRPC server
url: 'http://localhost:5000/api/v1/trpc/',
}),
],
});

export function trpc(queryClient?: QueryClient) {
return svelteQueryWrapper<Router>({
client,
queryClient,
});
return svelteQueryWrapper<Router>({
client,
queryClient,
});
}
```

Expand Down Expand Up @@ -166,11 +166,11 @@ The main thing that needs to passed in to `svelteQueryWrapper` is the `tRPC` cli
let browserClient: ReturnType<typeof createTRPCClient<Router>>;

export function trpc(init?: TRPCClientInit) {
const isBrowser = typeof window !== 'undefined';
if (isBrowser && browserClient) return browserClient;
const client = createTRPCClient<Router>({ init });
if (isBrowser) browserClient = client;
return client;
const isBrowser = typeof window !== 'undefined';
if (isBrowser && browserClient) return browserClient;
const client = createTRPCClient<Router>({ init });
if (isBrowser) browserClient = client;
return client;
}
```

Expand All @@ -183,14 +183,14 @@ import type { QueryClient } from '@tanstack/svelte-query';
let browserClient: ReturnType<typeof svelteQueryWrapper<Router>>;

export function trpc(init?: TRPCClientInit, queryClient?: QueryClient) {
const isBrowser = typeof window !== 'undefined';
if (isBrowser && browserClient) return browserClient;
const client = svelteQueryWrapper<Router>({
client: createTRPCClient<Router>({ init }),
queryClient,
});
if (isBrowser) browserClient = client;
return client;
const isBrowser = typeof window !== 'undefined';
if (isBrowser && browserClient) return browserClient;
const client = svelteQueryWrapper<Router>({
client: createTRPCClient<Router>({ init }),
queryClient,
});
if (isBrowser) browserClient = client;
return client;
}
```

Expand All @@ -214,16 +214,16 @@ import { trpc } from '$lib/trpc/client';
import type { PageLoad } from './$types';

export const load = (async (event) => {
const { queryClient } = await event.parent();
const client = trpc(event, queryClient);

return {
foo: await client.greeting.createServerQuery('foo'),
queries: await client.createServerQueries(
(t) =>
['bar', 'baz'].map((name) => t.greeting(name, { ssr: name !== 'baz' })) // pre-fetching disabled for the `baz` query.
),
};
const { queryClient } = await event.parent();
const client = trpc(event, queryClient);

return {
foo: await client.greeting.createServerQuery('foo'),
queries: await client.createServerQueries(
(t) =>
['bar', 'baz'].map((name) => t.greeting(name, { ssr: name !== 'baz' })) // pre-fetching disabled for the `baz` query.
),
};
}) satisfies PageLoad;
```

Expand Down

0 comments on commit fa0223b

Please sign in to comment.