RTK查询会将所有数据存储吗?如果是,为什么还需要将数据放入切片中?
不知道如何使用使用
use -elector
,我不知道为什么您需要创建,您需要创建Authslice并将令牌存储到authstate
中,如果RTK查询将所有数据放入商店/状态?
先感谢您
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为RTK查询不仅将数据放入商店中 - 还可以将它们删除。
60秒后,将删除您的应用程序未使用的查询缓存条目。
一旦突变组件卸下或触发另一个突变(因为在那时,就无法再获取数据。
因此数据并将其放置在某个地方,您会再次找到它,可以决定自己是否要删除。
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.