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
awexis
awexis16mo ago
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.
awexis
awexis16mo ago
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
JudgeJLo
JudgeJLo16mo ago
Odd. I literally tried that and I got an error about it being undefined. This is what I expected and works. Thanks.
awexis
awexis16mo ago
No problem 👍🏼
Want results from more Discord servers?
Add your server
More Posts
Why does react rerender this at the component level but not when using a hook?I've been toying with a type-writer effect in react and cant understand why react's lifecycle is worgetServersideProps not providing type inference, and session getting lost between server and clientI have this function (which I've used many times before), ```ts export const getServerSideProps: Getmiddleware does not run on index pageHere's the middleware config ```ts export const config = { matcher: [ /* * Match all requshould I use ctx or api?whats the difference between me using api.events.getEvent.cancel() vs ctx.events.getEvent.cancel()? react-table v7 globalFilters not workingI am writing a CRUD app with the t3 stack and react-table that basically fetches the data with tRPC I'm trying to change the image in my img tag (html tag not next component), but it's saying module nam I not importing it right>?Concrete guide for Credentials Provider with T3 + Next auth?I've been trying to implement the credentials provider with standard email + password authenticationDeploy app using Nodemailer-express-handlebars + nodemailer to send emails on vercel` ERROR [Error: ENOENT: no such file or directory, open '/var/task/src/mailer/templates/invite.htTurborepo & Prisma Environment VariablesHi, I'm currently setting up my Monorepo with Turborepo and env-vars are... weird.. with it. The prtypescript-eslint/no-misused-promises: how to handle Promise<void> in event handlers?<button onClick={someAsyncFetchFunction} />Click</button> This ESLint rule didn't squash the warnin