Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
2 replies
k

tRPC "Cannot destructure property 'client' of 'useContext(...)' as it is null"

i'm using create-t3-app. i'm trying to call my trpc endpoint from my frontend and i get
TypeError: Cannot destructure property 'client' of 'useContext(...)' as it is null.


i'm calling this in a client component in /pages so it's not an app directory not supporting context issue

backend code
export const getProjects = publicProcedure
  .input(z.object({ publicKey: z.string() }))
  .mutation(async ({ input, ctx: { prisma } }) => {
    const projects = await prisma.project.findMany({
      where: {
        client: {
          public_key: input.publicKey,
        },
      },
      select: {
        name: true,
      },
    });

    return projects;
  });


frontend code
const { mutate } = api.client.getProjects.useMutation();
image.png
Was this page helpful?