Skip to content

Commit

Permalink
feat: expose trpc types to client for app router (#1842)
Browse files Browse the repository at this point in the history
  • Loading branch information
nick22985 committed Apr 22, 2024
1 parent ff886b3 commit 088a773
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-hornets-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": minor
---

Infers tRPC input & output types to the client for app router
15 changes: 15 additions & 0 deletions cli/template/extras/src/trpc/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { loggerLink, unstable_httpBatchStreamLink } from "@trpc/client";
import { createTRPCReact } from "@trpc/react-query";
import { type inferRouterInputs, type inferRouterOutputs } from "@trpc/server";
import { useState } from "react";
import SuperJSON from "superjson";

Expand All @@ -22,6 +23,20 @@ const getQueryClient = () => {

export const api = createTRPCReact<AppRouter>();

/**
* Inference helper for inputs.
*
* @example type HelloInput = RouterInputs['example']['hello']
*/
export type RouterInputs = inferRouterInputs<AppRouter>;

/**
* Inference helper for outputs.
*
* @example type HelloOutput = RouterOutputs['example']['hello']
*/
export type RouterOutputs = inferRouterOutputs<AppRouter>;

export function TRPCReactProvider(props: { children: React.ReactNode }) {
const queryClient = getQueryClient();

Expand Down

0 comments on commit 088a773

Please sign in to comment.