0

My question will be based on this example: https://codesandbox.io/s/github/reduxjs/redux-toolkit/tree/master/examples/query/react/authentication-with-extrareducers?from-embed=&file=/src/app/services/auth.ts

Without knowing how to access the data fetched from RTK query using useSelector, I wonder why do you need to create authSlice and store the token into the AuthState, if RTK query put all the data into store/state?

Thank you in advance

bbnn
  • 3,505
  • 10
  • 50
  • 68

1 Answers1

2

Because RTK Query not only puts data into the store - it also removes them there.

A query cache entry that is not being used by your app any more will be removed after 60 seconds. A mutation result will be removed once the mutating component unmounts or triggers another mutation (since at that point there is no way of getting that data any more.

So if you want something to be "always around", you have to take control of that data and put it somewhere you will find it again and can decide yourself it is going to be removed or not.

phry
  • 35,762
  • 5
  • 67
  • 81