TypeError: Cannot read properties of null (reading 'useContext') when using useMutation with TRPC in
I'm encountering an error in my Next.js application when trying to use the useMutation hook with TRPC (Typed RPC) library. The error message I'm getting is "TypeError: Cannot read properties of null (reading 'useContext')". It seems to be related to the useContext hook, but I'm not sure how to resolve it.
Here's the relevant code snippet within a Next.js component, including the TRPC setup:
´´´ /// trpc router import { api } from "~/utils/api"; import { createTRPCRouter, publicProcedure } from "~/server/api/trpc"; import { input, z } from "zod";
I have checked the imports, dependencies, and the usage of the useMutation hook. However, I'm still encountering this error. I suspect it might be related to the interaction between the TRPC library and Next.js or the way I'm using the useMutation hook with TRPC.
Has anyone encountered a similar issue when using TRPC with Next.js? Any suggestions on what might be causing this error and how I can resolve it would be greatly appreciated.
Continue the conversation
Join the Discord to ask follow-up questions and connect with the community
t
tRPC
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.