tRPCttRPC
Powered by
kosilicaK
tRPC•3y ago•
4 replies
kosilica

useContext won't infer type from tRPC client

I am calling tRPC endpoints from my app and it's working flawlessly. As you can see on first screenshot it offers me autocompletion and queries return data from the server.

However on some other places I would like to read data from tRPC's global state using context. Following code works & I can get the data but there is no typesafety for useContext and also auto complete on utils thinks it is of string type (2nd screenshot).
const utils = apiClient.useContext();
const profileData = utils.user.getUserProfile.getData();
const utils = apiClient.useContext();
const profileData = utils.user.getUserProfile.getData();

Does anyone has idea what I am doing wrong? Please note that I am not going to use useQuery() and useContext() lines at the same spot, I just put them in same place for screenshots.
image.png
image.png
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

tRPC middleware infer type from another protectedProcedure
TTT / ❓-help
3y ago
How can I infer the trpc.procedure.mutationOptions type?
AnonTGAAnonTG / ❓-help
2mo ago