RTK查询 - 单个端点的不变性
我在项目中介绍了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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,肯定没有办法禁用单个端点的冻结。 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 usescreateSlice
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.