I'm using tRPC to fetch my data to the client. tRPC uses React Query as a dev dependency so I got that installed too. Since my app is rather small, I'm choosing to not use Redux. I read that React Query can cache data using their QueryClient API. This means that I have to set and get the data manually after each fetch/mutation. At the same time I also have to create additional types for the data when getting data from cache, which defeats the purpose of a using tRPC since all the types lives there. Am I missing anything on caching when using tRPC?
Asked
Active
Viewed 3,385 times
1 Answers
6
You don't have to set/get from the cache manually. React-Query handles that by default, so when a request to the same route is made, React-Query will automatically return from the cached results instead of making another request to the server.

juliomalves
- 42,130
- 20
- 150
- 146

Om Budhiraja
- 84
- 3
-
What if multiple requests are sent before first one is resolved? Will it only send the request once, and will all following requests wait to be resolved? – Davo Apr 25 '23 at 12:49