英文:
Redux Toolkit Query status deprecated
问题
我曾使用redux-toolkit/query中的status标志来指示状态是pending还是fulfilled还是rejected,但现在status已被弃用。如何使用isLoading、isFetching、isSuccess的组合来获取查询状态?
我认为当isLoading和isFetching都为false,而isSuccess为true时,查询已成功?
const {
  data,
  isLoading,
  isError,
  isFetching,
  isSuccess,
  status
} = useGetUsersQuery()
(Note: The code portion is not translated as per your request.)
英文:
I was using the status flag in the redux-toolkit/query to indicate if the state is pending or fulfilled or rejected, but status is now deprecated. How can I use the combination of isLoading, isFetching, isSuccess to get the query state?
I think when isLoading and isFetching are false and isSuccess is true, then it is fullfilled?
const {
  data,
  isLoading,
  isError,
  isFetching,
  isSuccess,
  status
} = useGetUsersQuery()
答案1
得分: 0
你的const到目前为止还不错。在这种情况下,我会通过简单地使用if语句来解决这个问题。也许你可以使用类似这样的处理来采取行动:
if (isLoading || isFetching) { ... }
else if (isSuccess) { ... }
else if (isError) { ... }
对于这个,你可以根据你的状态继续你喜欢的操作。
英文:
Your const is fine so far. I would solve solve this by simply using if-statements in that case. So maybe you could use some handling like this to take action:
if (isLoading || isFetching) { ... }
else if (isSuccess) { ... }
else if (isError) { ... }
For this you can proceed on your prefered action you want to do based on your state.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论