Search code examples
reactjsrtk-query

RTK Query how to not run transformResponse if cached data is used


I am running RTKQ with transformResponse on a set of data that is not that time senstive and doesn't change often. That is, I only need to refresh it few times, or even just once in the entire app.

Let's say, I set createApi{ keepUnusedDataFor: 60*60*12, ... //12 hrs.

However, every time when the data is used, transformResponse will run the unnecessary transform loops on the same old cache data anyway:

transformResponse: response => response.data.map(item=> ... //data looping & transforming

My question is, since my cache data did not re-fetch and did not change, is there a way to tell the transformResponse not to run it again?


Solution

  • As you can see in the source code, transformResponse only runs directly after a request was made and the response was received from the server. There must be something wrong going on in your application.