TRPC async promise return type
Hello I am having some trouble with the types of the return values from the trpc router. I am unsure how to properly type and resolve this promise type error.
I have a navbar component that I am calling the trpc router for the categories I am pulling from my db and ive awaited that call
And I am calling the router here
In the plugin dropdown I also have already created an interface (although not sure if this is the right way to do it)
How can I resolve my type error on the categories prop? Any help is really appreciated!
5 Replies
when you use a query, the response isn't immediate
if you have check if there is data for the component to accept
you can check if isnt loading and has data
or use
categoriesQuery.data ?? []
Yeah I think thats the part where im struggling a little bit . I tried using the but i wasnt able to resolve the error via that.
I am trying to check if it has data before it passes the data to the component but im still getting the same results
try removing the z.promise
you "cant ship" a promise with trpc
Ahh understood! That actually resolved it for me. Really appreciate you chiming in 🙏 was going in circles
glad to help