Redux Toolkit Query status deprecated

huangapple go评论67阅读模式
英文:

Redux Toolkit Query status deprecated

问题

我曾使用redux-toolkit/query中的status标志来指示状态是pending还是fulfilled还是rejected,但现在status已被弃用。如何使用isLoadingisFetchingisSuccess的组合来获取查询状态?

我认为当isLoadingisFetching都为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.

huangapple
  • 本文由 发表于 2023年3月9日 19:51:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75684228.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定