如何缓存NextJ和TRPC中的状态管理数据?

发布于 2025-02-12 00:01:02 字数 221 浏览 1 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑忘罢 2025-02-19 00:01:02

您不必手动从缓存中设置/获取。 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文