return type of a query endpoint
Hello
I currently have a trpc endpoint:
And I am trying to pass this into a custom react component:
The problem is, I'm not entirely sure how I am supposed to type the
customInstance
property? I have tried using return types:
but this makes the data
property value unknown
.5 Replies
Inferring Types | tRPC
In addition to the type inference made available by @trpc/server (see here) this integration also provides some inference helpers for usage purely in React.
Thank you!
I wouldn't pass around the whole Query object, prefer writing interfaces which can be re-used and you'll make components easier to re-use, particularly for testing
I'd have a data prop and a refetch prop for your use-case, though needing to refetch() at all is sometimes (maybe not here) a sign you're doing something a bit wrong with react-query
That also means you can host on other adapters too. Coupling is often bad
Sorry, I just saw these messages.
At the moment I mainly use refetch to update the response once something has been updated/deleted. I should probably just return the updated document in the response to the mutation, or in the case of a delete just remove it from the original data list. Would be more efficient for sure.
In react query you can use invalidate for that purpose, this will invalidate the query and fetch from server. Invalidate is available on the useContext of trpc.