RTK查询 - 单个端点的不变性

发布于 2025-01-30 13:43:35 字数 282 浏览 2 评论 0原文

我在项目中介绍了RTK查询。但是,从一个端点检索到的数据(使用createapi创建)被馈送到D3库中,该库立即开始突变数据。由于RTKQ返回不变的数据,因此D3丢弃一个错误,说对象不是可扩展的。因此,我的问题是

有没有办法可以将RTKQ的不变性用于特定端点?

我了解我可以复制检索到的数据&使用路线的副本,但我想避免这样做。

请注意,数据不是应用程序状态的一部分“ rel =“ nofollow noreferrer”> docs 。

I'm introducing RTK Query in my project. However, the data retrieved from one endpoint (created with createApi) is fed to the D3 library which immediately starts to mutate the data. Since RTKQ returns immutable data, D3 throws an error saying object is not extensible. So my question is

Is there a way to disable immutability with RTKQ for a particular endpoint?

I understand that I can copy the retrieved data & use the copy down the road but I would like to avoid doing it.

Note, that the data is not part of the application state so I cannot disable immutability with ignoredPaths as described in the docs.

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

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

发布评论

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

评论(1

独行侠 2025-02-06 13:43:35

不,肯定没有办法禁用单个端点的冻结。 RTK使用浸入使用createSlice的所有还原器,RTKQ使用createSlice以生成其缓存还原器,并且 all> ALL CACHE数据都进入了该还原器。因此,浸入将冻结所有数据。

另外,请注意,您链接的不变性检查中间件与在还原器中的沉浸式冷冻状态不同。

在UI层上复制数据,例如usememo(),将是您在这里的最佳选择。

No, there's definitely no way to disable freezing for a single endpoint. RTK uses Immer for all reducers made with createSlice, RTKQ uses createSlice to generate its caching reducers, and all cache data goes into that reducer. So, Immer will freeze all that data.

Also, note that the immutability check middleware you linked is a different piece than Immer freezing state in reducers.

Copying the data at the UI layer, say in a useMemo(), is going to be your best option here.

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