如何缓存NextJ和TRPC中的状态管理数据?
我正在使用TRPC将数据获取给客户端。 TRPC将React查询用作DEV依赖性,因此我也安装了该问题。由于我的应用程序很小,因此我选择不使用Redux。我读到React查询可以使用其QueryClient API缓存数据。这意味着我必须在每个获取/突变之后手动设置并获取数据。同时,我还必须在从缓存中获取数据时为数据创建其他类型,因为所有类型都居住在此处,这会破坏使用TRPC的目的。使用TRPC时,我是否缺少任何缓存的内容?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不必手动从缓存中设置/获取。 React-Query处理默认情况下,因此,当提出对同一路由的请求时,React-Query将自动从缓存的结果返回,而不是向服务器提出另一个请求。
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.