【问题标题】:how to access the whole cache in "updateCachedData" RTK Query如何在 \"updateCachedData\" RTK 查询中访问整个缓存
【发布时间】:2023-02-06 08:50:52
【问题描述】:

我的组件中有一个无限滚动条。 我使用网络套接字连接实时更新数据。

假设我每页有 10 个项目,现在我在第 2 页。

当我想基于 web 套接字更新前 10 个项目中的一个项目时,我无法访问前 10 个项目,因为我在第 2 页,updateCachedData我只能访问页面的结果2.

那我该如何解决呢?


page 1 = [{a: 1}, {b: 1}, {c: 1}];
page 2 = [{e: 1}, {f: 1}, {g: 1}];

when page = 2;

updateCachedData(draft => {

// draft shows [{e: 1}, {f: 1}, {g: 1}];
// but I need to update page 1 to [{a: 1}, {b: 5}, {c: 1}]
// so when the user back to page 1, he can see the updated value.

})

【问题讨论】:

    标签: reactjs redux rtk-query rtk


    【解决方案1】:

    RTK 查询还有一个 updateQueryData API util thunk,它可以与缓存键一起调度以更新特定的缓存条目:

    【讨论】:

      猜你喜欢
      • 2022-07-10
      • 2021-11-01
      • 2023-02-16
      • 2022-11-05
      • 2021-11-06
      • 2022-08-03
      • 2023-01-27
      • 2022-07-27
      • 2023-02-05
      相关资源
      最近更新 更多