bill92
bill92
Explore posts from servers
TtRPC
Created by bill92 on 10/12/2024 in #❓-help
Network tab returns array but data is undefined
No description
4 replies
TtRPC
Created by bill92 on 9/18/2024 in #❓-help
Infer query type of `data`
Using trpc version 11, how can I infer data?
const { isLoading, isError, error, data } =
trpc.patient.list.useQuery();

<SomeComponent data={data} />
const { isLoading, isError, error, data } =
trpc.patient.list.useQuery();

<SomeComponent data={data} />
Are there any utils on doing so? I've seen export type PatientData = inferRouterOutputs<ApiRouter>; but it doesn't work any help?
3 replies
TtRPC
Created by bill92 on 5/24/2024 in #❓-help
conditional useQuery without input
How to use the enabled option for useQuery that doesn't has an input?
const { isError, error } = trpc.iam.logout.useQuery(undefined, {
enabled: isEnabled,
});
const { isError, error } = trpc.iam.logout.useQuery(undefined, {
enabled: isEnabled,
});
I'm passing undefined and TS is not complaining, only on runtime I get app-index.js:33 Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: [["iam","logout"],{"type":"query"}] How to properly use this feature?
6 replies
TtRPC
Created by bill92 on 5/9/2024 in #❓-help
Error calling middleware
I'm getting an error trying to test out some pretty basic middleware. This is my code
export const createContext = ({
req,
res,
}: trpcExpress.CreateExpressContextOptions) => ({ prisma, res, req });

const t = initTRPC.context<Context>().create();

export const router = t.router;
export const procedure = t.procedure;

export const middleware = procedure.use(async (opts) => {
console.log('middleware');
return opts.next(opts);
});

export const authRouter = router({
me: middleware.query(async ({ ctx }) => {
console.log(ctx.req.headers.cookie);
return { success: true };
}),
});
export const createContext = ({
req,
res,
}: trpcExpress.CreateExpressContextOptions) => ({ prisma, res, req });

const t = initTRPC.context<Context>().create();

export const router = t.router;
export const procedure = t.procedure;

export const middleware = procedure.use(async (opts) => {
console.log('middleware');
return opts.next(opts);
});

export const authRouter = router({
me: middleware.query(async ({ ctx }) => {
console.log(ctx.req.headers.cookie);
return { success: true };
}),
});
Getting TypeError: Cannot read properties of undefined (reading 'use') I'm following the documentation [https://trpc.io/docs/server/middlewares] and I'm using @trpc/server@next
3 replies