kosilicaK
tRPC3y 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();

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
Was this page helpful?