Typing Props
I have a query that is returning an array of items. I'm then mapping over that array and rendering elements in a child component. I did some wacky stuff to get the type from the api but that felt VERY wrong. Currently just passing an id and refetching inside the child, but that also seems wrong. What is the best practice here?
4 Replies
If you're using tRPC which it seems like it. They have a type helper to infer the type. https://trpc.io/docs/infer-types#additional-dx-helper-type
Inferring Types | tRPC
It is often useful to wrap functionality of your @trpc/client or @trpc/react-query api within other functions. For this purpose, it's necessary to be able to infer input types and output types generated by your @trpc/server router.
Where i think you can just pass Goal as a prop instead of the ID and re-fetching
RouterOutput["goals"]["getOne"] from looking at the code
Odd. I literally tried that and I got an error about it being undefined. This is what I expected and works. Thanks.
No problem 👍🏼