如何使用RTK Query查询返回的缓存数据

发布于 2025-02-05 06:23:22 字数 620 浏览 1 评论 0原文

我有一个React-toolkit查询,在第一个成功的请求之后,请求将响应按预期缓存,然后在随后的请求中使用缓存的响应。我很好。

在商店中,我有一个切片,它正在观看上述查询,以实现匹配以获取响应并将其转换为然后在切片的状态下保存一些处理。

问题是:第一次提出请求,我可以通过匹配器获得响应,但是在随后的呼叫中,匹配器不匹配满足,因为请求已缓存并且没有执行,但我需要将数据获取在slice中,我该怎么办?

这是一个示例代码:

const itemsSlice = createSlice({
   name: 'items',
   initialState,
   reducers: {},
   extraReducers: builder => {
      builder.addMatcher(api.endpoints.getTokens.matchFulfilled, (state, {payload}) => {
         // process the payload and update slice's state
      })
   }
})

I have a react-toolkit query that after a first successful request cached the response as expected, then in subsequent requests it's using the cached response. I'm ok with that.

In the store I have a slice that is watching the above mentioned query for matching fulfilled to get the response and transform it to then save some processed in the slice's state.

The problem is this: The first time the request is made I can get the response through a matcher, but then in subsequent calls the matcher do not match fulfilled cause the request is cached and no executed but I need to get the data in the slice, how can I?

This is a sample code:

const itemsSlice = createSlice({
   name: 'items',
   initialState,
   reducers: {},
   extraReducers: builder => {
      builder.addMatcher(api.endpoints.getTokens.matchFulfilled, (state, {payload}) => {
         // process the payload and update slice's state
      })
   }
})

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文