Closed jontmy closed 1 year ago
We currently do not support the app dir.
My guess to why what you're doing isn't working: The tRPC client requires some providers to work. In Create T3 App we use the withTRPC
higher order component that includes these providers. I doubt this would currently work in the app dir because you need to wrap the entire app and it's fundamentally different.
I think a "normal" React implication (see docs) might work in a client component. But I haven't tried it, so no promises.
I have come across the same issue using appDir. The issue does not persist on production environment only in development in my case.
Just incase anyone else comes across this issue, here's a trpc setup that works with next13 - https://github.com/wpcodevo/nextjs13-trpc-setup
Provide environment information
Describe the bug
I've been experimenting with using tRPC when incrementally adopting the
/app
directory.Using the
api
variable fromutils/api
in any page in the app directory results in "TypeError: useContext() is null".I'm particularly stumped because TypeScript does not emit any type errors in the IDE.
Is the use of tRPC in the app directory currently unsupported? Apologies if this is not the right use case, I've only been trying out the T3 stack recently.
Reproduction repo
https://github.com/jontmy/t3-err
To reproduce
from
create-t3-app
npx create-t3-app
with TypeScript and all packages, and the default~
alias.next.config.mjs
, comment out thei18n
lines and enable the appDir.src/app/test/page.tsx
and the directories along the path.test/page.tsx
. It's derived from the parts ofpages/index.tsx
that display "Hello from tRPC".import {api} from "~/utils/api";
const UserPage = () => { const hello = api.example.hello.useQuery({text: "from tRPC"});
}; export default UserPage
error - node_modules\@trpc\react-query\dist\createHooksInternal-416876ed.mjs (341:16) @ Object.useQuery$1 [as useQuery] error - TypeError: Cannot destructure property 'abortOnUnmount' of 'useContext(...)' as it is null. at UserPage (./src/app/test/page.tsx:11:77)