-
While I work on my project using For your convenience, here is code snippet in the above link: function Child() {
const { isLoading, isFetching } = useQuery({
queryKey: ["querykey"],
queryFn: async () =>
new Promise((res) => {
console.log("start fetching");
setTimeout(() => {
console.log("fetched");
res("data");
}, 3000);
})
});
const isLoadingFromHook = useIsFetching({
queryKey: ["querykey"],
predicate: (query) => query.state.status === "loading"
});
const isFetchingFromHook = useIsFetching({
queryKey: ["querykey"]
});
useEffect(() => {
console.log({
isLoading,
isFetching,
isLoadingFromHook,
isFetchingFromHook
});
}, [isLoading, isFetching, isLoadingFromHook, isFetchingFromHook]);
return <div>Child</div>;
} And the logs are:
As you can see, there are some cases that |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If we wouldn't do that, every place where you had The
So it's kinda intended. Hope that explains it :) |
Beta Was this translation helpful? Give feedback.
useQuery
"optimistically" gets you into loading / fetching state when it knows that it will trigger a fetch "soon". E.g. on the first render, we give you backfetching: true
even though we haven't fetched yet, as this has to happen in aneffect
under the hood.If we wouldn't do that, every place where you had
useQuery
would give you back a render wherefetching
would befalse
, followed by an immediate one wherefetching
istrue
.The
useIsFetching
hook on the other hand cannot do that because it doesn't have that information.isLoadingFromHook
is also0
becauseuseIsFetching
implicitly checks forfetching
state :)So it's kinda intended. Hope that explains it :)