cacheTime loading states
Describe the bug
Setting cacheTime: 0 doesn't set the loading state to true when refetched
To Reproduce Steps to reproduce the behavior:
- Go to https://codesandbox.io/s/ecstatic-cray-uobv0?file=/src/App.tsx
- Click on the
twolink and watch the console isLoadingis never set totruewhen clicking back and forth fromroottotworoutes
Expected behavior
If setting cacheTime: 0 I would expect that the fetch gets recalled and the loadings states are true until the fetch resolves.
Desktop (please complete the following information):
- OS: macOS
- Browser: chrome
- Version: 86.0.4240.111
Additional context Add any other context about the problem here.
Thanks for reporting! Fixed in 3.2.0-beta.12
@boschni will this be fixed in v2?
@boschni any thoughts on this being fixed in v2? Sorry to bug I have a large project in running v2.
Sure you are not able to use staleTime 0 together with isFetching?
Op 26 okt. 2020 om 15:23 heeft John Long [email protected] het volgende geschreven:
 @boschni any thoughts on this being fixed in v2? Sorry to bug I have a large project in running v2.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
I've tried both
const { isLoading, error, data } = useQuery(
"repo",
() =>
fetch(
"https://api.github.com/repos/tannerlinsley/react-query"
).then((res) => res.json()),
{
cacheTime: 0,
staleTime: 0
}
);
and
const { isLoading, error, data } = useQuery(
"repo",
() =>
fetch(
"https://api.github.com/repos/tannerlinsley/react-query"
).then((res) => res.json()),
{
staleTime: 0
}
);
with the same issue. https://codesandbox.io/s/optimistic-bohr-bh9dk?file=/src/App.tsx
It also gets stuck in a infinite loop making requests on iOS safari.
What if you try to use isFetching instead of isLoading?
@boschni things are working correctly here https://codesandbox.io/s/goofy-tharp-h5ifu
I had to update the cache key to use an id ["repo", id]. Using a static query key like "repo" seems to not respect cacheTime or staleTime, not sure if that's by design?
Changing the query key should not matter, but the cacheTime is generally not used and should not be changed most of the time, staleTime: 0 should be enough.