0

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.

sherlaimov
  • 29
  • 1
  • 5

1 Answers1

1

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.

markerikson
  • 63,178
  • 10
  • 141
  • 157
  • thank you for the answer. I'm still thinking how to implement this in the most elegant way. At this point I'm considering simply not using RTKQ for this particular endpoint at all. – sherlaimov May 20 '22 at 08:13