Eternal Mori
Eternal Mori2y ago

How can I make a direct fetch on a router endpoint from TRPC in NextJS on client?

In the documentation you can use the vanilla TRPC client like this:
const bilbo = await client.getUser.query('id_bilbo');
const bilbo = await client.getUser.query('id_bilbo');
But with NextJS app is wrapped with the WithTRPC wrapper. where you can only use hooks. How can I make a direct call?
1 Reply
NEO
NEO2y ago
useContext | tRPC
useContext is a hook that gives you access to helpers that let you manage the cached data of the queries you execute via @trpc/react-query. These helpers are actually thin wrappers around @tanstack/react-query's queryClient methods. If you want more in-depth information about options and usage patterns for useContext helpers than what we provide...