Type of createServerSideHelpers?

I'm currently trying to implement a helper for getServerSideProps to reduce duplication. It's still wip, but I'm encountering a problem I can't figure out:
export async function createServerSideProps(
ctx: GetServerSidePropsContext,
callback: (helpers/**: ???? */) => Record<string, any>
) {
const helpers = createServerSideHelpers({
router: appRouter,
ctx: {
user: await getServerSession(ctx.req, ctx.res, authOptions),
},
transformer: superjson,
});

const props = callback(helpers);

return {
props,
};
}
export async function createServerSideProps(
ctx: GetServerSidePropsContext,
callback: (helpers/**: ???? */) => Record<string, any>
) {
const helpers = createServerSideHelpers({
router: appRouter,
ctx: {
user: await getServerSession(ctx.req, ctx.res, authOptions),
},
transformer: superjson,
});

const props = callback(helpers);

return {
props,
};
}
What's the type of helpers in the callback?
N
nehalist368d ago
Figured it out myself:
export async function createServerSideProps(
ctx: GetServerSidePropsContext,
callback: (
helpers: DecoratedProcedureSSGRecord<AppRouter>
) => Record<string, any>
) {
const helpers = createServerSideHelpers({
router: appRouter,
ctx: {
user: await getServerSession(ctx.req, ctx.res, authOptions),
},
transformer: superjson,
});

const props = await callback(helpers);

return {
props: {
trpcState: helpers.dehydrate(),
...props,
},
};
}
export async function createServerSideProps(
ctx: GetServerSidePropsContext,
callback: (
helpers: DecoratedProcedureSSGRecord<AppRouter>
) => Record<string, any>
) {
const helpers = createServerSideHelpers({
router: appRouter,
ctx: {
user: await getServerSession(ctx.req, ctx.res, authOptions),
},
transformer: superjson,
});

const props = await callback(helpers);

return {
props: {
trpcState: helpers.dehydrate(),
...props,
},
};
}
B
bigshot824351d ago
Hello bro.. How do you implement this and where did you put the code? I just got an error "PrismaClient is unable to be run in the browser" [next js]
B
bigshot824351d ago
this is how I apply. @nehalist
N
nehalist351d ago
seems like somewhere in your code you're referencing prisma on the client
B
bigshot824351d ago
hmMmMm... I'll take a look on that and let you know 👍
More Posts
how to set request timeout in clientcreateProxyClient has no option about timeout like axios does. Just in one router request (query or trpc rate limitinghi I am currently having some problems with a race condition in my TRPC nextJS api. Essentially whtrpc pipe middlewareHey all. I'm currently trying to create a middle ware on endpoints using the new `pipe` API. This Has anyone ever used tRPC (with SSR) and i18n?No matter the lib (next-intl, next-i18n, next-translate), I simply stumble from one problem to anothNew to tRPC and Need Help with BasicsI made a new T3 app, but I don't quite understand how tRPC works, and I would love to get some help web socket keeps on disconnecting and connectingHi! Its my first time using web sockets. The first code snippet is my socket code. The second code sPagination QueryHi, I'm new for web dev and I'm moved to tRPC not so long I'm looking for example of pagination quEnrich the response object for TRPC endpointCurrently when I hit a trpc endpoint I get something like: ```typescript { result: { data:Can i fetch tRPC in different project@coco- : I Make a tRPC in my project. Can I use the enpoint api in different project ?Importing AppRouter types from an external repoI've got a production T3 app already in production. I've created a fresh expo app to start building TypeScript type for request object for route handlersSo far I've been writing my routes like: ```typescript export const router = t.router({ helloWorlTyped wrappers for proceduresI have a TRPC client with working queries and mutations. I wanted to create wrapper functions for al