File tree Expand file tree Collapse file tree 12 files changed +79
-25
lines changed
Expand file tree Collapse file tree 12 files changed +79
-25
lines changed Original file line number Diff line number Diff line change 1515# production
1616/build
1717
18+ .turbo
19+
1820# misc
1921.DS_Store
2022* .pem
Original file line number Diff line number Diff line change @@ -173,10 +173,10 @@ export const createContext = async () => {
173173const ctx = new CtxRouter <Awaited <ReturnType <typeof createContext >>>();
174174
175175export const appRouter = ctx .router ({
176- getUser: endpoint .action (async ({ db }) => {
176+ getUser: ctx . endpoint .action (async ({ db }) => {
177177 return await db .user .get ();
178178 }),
179- greeting: endpoint
179+ greeting: ctx . endpoint
180180 .input (
181181 // you can add zod typechecking to your entry params
182182 z .object ({
@@ -192,6 +192,9 @@ export const appRouter = ctx.router({
192192export type AppRouter = typeof appRouter ;
193193```
194194
195+ > [ !NOTE]
196+ > Param types are serialized during the http request to the api. You need to use ` z.coerce ` for non-string types.
197+
195198Next pass your context to the nextjs api endpoint.
196199
197200` app/api/trpc/[trpc]/route.ts `
Original file line number Diff line number Diff line change 11import type { Metadata } from "next" ;
22import { Geist , Geist_Mono } from "next/font/google" ;
33import "./globals.css" ;
4+ import { ReactQueryProvider } from "~/components/query-client" ;
45
56const geistSans = Geist ( {
67 variable : "--font-geist-sans" ,
@@ -27,7 +28,7 @@ export default function RootLayout({
2728 < body
2829 className = { `${ geistSans . variable } ${ geistMono . variable } antialiased` }
2930 >
30- { children }
31+ < ReactQueryProvider > { children } </ ReactQueryProvider >
3132 </ body >
3233 </ html >
3334 ) ;
Original file line number Diff line number Diff line change 11"use server" ;
22
33import { serverTrpc } from "~/trpc/server-client" ;
4- import { ClientComp } from "./client-comp" ;
4+ import { ClientComp } from "../components /client-comp" ;
55
66export default async function Home ( ) {
77 const user = await serverTrpc . getUser . fetch ( ) ;
File renamed without changes.
Original file line number Diff line number Diff line change 1+ 'use client' ;
2+
3+ import { useState } from 'react' ;
4+
5+ import { QueryClient , QueryClientProvider } from '@tanstack/react-query' ;
6+
7+ export function ReactQueryProvider ( props : React . PropsWithChildren ) {
8+ const [ queryClient ] = useState (
9+ ( ) =>
10+ new QueryClient ( {
11+ defaultOptions : {
12+ queries : {
13+ // With SSR, we usually want to set some default staleTime
14+ // above 0 to avoid refetching immediately on the client
15+ staleTime : 60 * 1000 ,
16+ } ,
17+ } ,
18+ } ) ,
19+ ) ;
20+
21+ return (
22+ < QueryClientProvider client = { queryClient } >
23+ { props . children }
24+ </ QueryClientProvider >
25+ ) ;
26+ }
Original file line number Diff line number Diff line change 1010 "lint" : " eslint"
1111 },
1212 "dependencies" : {
13+ "@tanstack/react-query" : " ^5.90.12" ,
1314 "next" : " 16.0.8" ,
1415 "react" : " 19.2.1" ,
15- "react-dom" : " 19.2.1"
16+ "react-dom" : " 19.2.1" ,
17+ "zod" : " ^3.25.76"
1618 },
1719 "devDependencies" : {
1820 "@tailwindcss/postcss" : " ^4" ,
2224 "eslint" : " ^9" ,
2325 "eslint-config-next" : " 16.0.8" ,
2426 "tailwindcss" : " ^4" ,
25- "typescript" : " ^5"
27+ "typescript" : " ^5.9.3 "
2628 }
2729}
Original file line number Diff line number Diff line change 1- import { CtxRouter , endpoint } from "../../src/core" ;
1+ import { CtxRouter } from "../../src/core" ;
22import z from "zod" ;
33
44export const createContext = async ( ) => {
@@ -11,7 +11,7 @@ export const createContext = async () => {
1111const ctx = new CtxRouter < Awaited < ReturnType < typeof createContext > > > ( ) ;
1212
1313export const appRouter = ctx . router ( {
14- getUser : endpoint . action ( async ( { hello, howAreYou, request } ) => {
14+ getUser : ctx . endpoint . action ( async ( { hello, howAreYou, request } ) => {
1515 console . log ( {
1616 myCustomContext : {
1717 hello,
@@ -31,7 +31,7 @@ export const appRouter = ctx.router({
3131 } , 1000 ) ;
3232 } ) ;
3333 } ) ,
34- greeting : endpoint
34+ greeting : ctx . endpoint
3535 . input (
3636 z . object ( {
3737 name : z . string ( ) ,
@@ -42,7 +42,7 @@ export const appRouter = ctx.router({
4242 console . log ( { howAreYou } ) ;
4343 return `Hi my name is ${ name } , and I am ${ age } years old.` ;
4444 } ) ,
45- test : endpoint . action ( async ( { hello, howAreYou, request } ) => {
45+ test : ctx . endpoint . action ( async ( { hello, howAreYou, request } ) => {
4646
4747 return new Promise ( ( resolve ) => {
4848 setTimeout ( ( ) => {
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import "server-only";
33import { createTrpcClient } from "../../src/create-trpc-client" ;
44import { AppRouter } from "./router" ;
55
6- const url = "https ://localhost:3000/api/trpc" ;
6+ const url = "http ://localhost:3000/api/trpc" ;
77
88export const serverTrpc = createTrpcClient < AppRouter > ( {
99 url,
Original file line number Diff line number Diff line change 11{
22 "name" : " @creatorem/next-trpc" ,
3- "type" : " module" ,
4- "version" : " 1.0.3" ,
3+ "version" : " 1.0.4" ,
54 "repository" : {
65 "type" : " git" ,
76 "url" : " git+https://github.com/creatorem/next-trpc"
2423 " dist"
2524 ],
2625 "scripts" : {
27- "build" : " tsc --noEmit false --outDir dist --declaration" ,
26+ "build" : " tsc --noEmit false --outDir dist --declaration --module commonjs --target ES2017 " ,
2827 "clean" : " git clean -xdf .turbo dist node_modules" ,
2928 "format" : " prettier --check \" **/*.{ts,tsx}\" " ,
3029 "lint" : " eslint ." ,
3534 },
3635 "exports" : {
3736 "." : {
37+ "import" : " ./dist/core.js" ,
3838 "require" : " ./dist/core.js" ,
3939 "types" : " ./dist/core.d.ts"
4040 },
4141 "./server" : {
42+ "import" : " ./dist/create-trpc-api.js" ,
4243 "require" : " ./dist/create-trpc-api.js" ,
4344 "types" : " ./dist/create-trpc-api.d.ts"
4445 },
4546 "./client" : {
47+ "import" : " ./dist/create-trpc-client.js" ,
4648 "require" : " ./dist/create-trpc-client.js" ,
4749 "types" : " ./dist/create-trpc-client.d.ts"
4850 },
4951 "./query-client" : {
52+ "import" : " ./dist/create-trpc-query-client.js" ,
5053 "require" : " ./dist/create-trpc-query-client.js" ,
5154 "types" : " ./dist/create-trpc-query-client.d.ts"
5255 }
6467 "typesVersions" : {
6568 "*" : {
6669 "*" : [
67- " src /*"
70+ " dist /*"
6871 ]
6972 }
7073 }
You can’t perform that action at this time.
0 commit comments