如何使用RTK Query查询返回的缓存数据
我有一个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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论