redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

RTKQ resetApiState is not properly resetting queries when skip=true

Open RRaideRR opened this issue 2 years ago • 2 comments

CodeSandbox

  1. I load the sandbox, the pokemon is fetched.
  2. I toggle skip (skip is true), the results will vanish.
  3. I reset the API state.
  4. Now I toggle skip again (skip is false).

I would expect that (because I made a reset of the API state) that there is no cached data. However, there is.

The documentation of resetApiState states that "Note that hooks also track state in local component state and might not fully be reset by resetApiState.".

Maybe my confusion can be explained with this - so I'm not quite sure if the above is really a bug or intended behavior.

RRaideRR avatar Apr 21 '23 13:04 RRaideRR

From my experience, don't call resetApiState unless you are definitely sure there are no actively subscribed queries. So most likely you'd want to unmount/unsubscribe all components that use RTK Query hooks before calling resetApiState.

andrejpavlovic avatar Sep 11 '23 19:09 andrejpavlovic

Updated the codesandbox to use the latest @reduxjs/toolkit release.

RRaideRR avatar Mar 06 '24 09:03 RRaideRR