admin管理员组文章数量:1294708
I am using v4 of useQuery
to poll and re-poll an endpoint until the correct data is fetched, or until a max re-poll count has been met.
However, I'm not sure how I can most effectively that the loading/re-polling is finished at the point where either:
- Received all of the data I need in order to progress (may be less re-polls than the max)
- Reached my max re-poll limit
Currently I am using a useState
to capture whether it's still polling:
const [isPolling, setIsPolling] = useState(true);
and changing the value of this within the refetchInterval
based on whether I am at the maximum re-poll limit, or if I have the data I need.
refetchInterval: (result, query) => {
const pollingEnded = result.data.stillWaitingForResults || query.state.dataUpdateCount < MAX_RE_POLL_COUNT;
setIsPolling(!pollingEnded);
return hasPollingEnded ? false : REFETCH_INTERVAL;
},
This is then used to return an object to show if the useQuery function is still polling etc.
return {
isLoading: isPolling,
...
}
However, I'm not entirely sure that this is the "correct" way to do this.
I know that there are several props as part of the request result that can indicate the status of the useQuery call, such as:
fetchStatus
- "fetching" whenever queryFn is executing, including initial loading and background fetchesisFetching
- Derived from thefetchStatus
isLoading
- Derived from thestatus
isRefetching
- True whenever background refetching (does not include initial loading) - Equivalent toisFetching && !isLoading
Is there a better way in which I can achieve this with the props returned by the useQuery, as I'm not 100% clear which would show all the loading statuses of the query such as initial and refetch poll?
本文标签: javascriptShow useQuery is still polling when either initial fetch or refetchStack Overflow
版权声明:本文标题:javascript - Show useQuery is still polling when either initial fetch or refetch? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741603723a2387849.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论