Comments (10)
It's because it's cached.
from query.
With react-query, when new component that use useQuery
mounted, the data cached in queryClient
with the same key in useQuery
will returned for rendering and at the time refetching new data at the background. from the users pecpective, they saw cached data immediately and will see content update if the refetching return different data. The cache behavior is the same for angular query, but not the refetching behavior.
from query.
In your react application, could you try setting in the global query config the staleTime
to Infinity
and tell me if it still works the same?
from query.
After setting staleTime
to Infinity
, the query won't refetch on re-mounted. so, In my Angular application, after setting the stateTime
of useQuery
to 0
, it will refetch automatically when component re-mounted.
getTodos() {
return this.#useQuery(
['todos', 'list'],
() => {
return getTodos();
},
{ staleTime: 0 }
);
}
In according to the reference of useQuery in the docs, staleTime
is default to 0
. I wondered why the default is different in angular query, just curious.
from query.
It's just a hunch based on my usage. But now I wonder if it's better to leave the default as react-query to avoid future discussions like this.
from query.
Now I also wonder if it's the same issue here - #56
Can you check it with staleTime
set to 0, please?
from query.
Sure, and after setting options like this
getTodos() {
return this.#useQuery(
['todos', 'list'],
() => {
return getTodos();
},
{ staleTime: 0, refetchOnWindowFocus: true }
);
}
The query still won't refrech on windows focus. no matter refetchOnWindowFocus
set to true
or "always"
.
from query.
Thanks. I'll remove the default staleTime that we set.
from query.
@NetanelBasal Thanks for your response. I'll close this issue.
from query.
Done
from query.
Related Issues (20)
- SSR snippets outdated? HOT 1
- provideQueryClientOptions changes behaviour of queries even when not changing any default properties HOT 2
- Add `mapResultsData` operator to `README.md` and the playground
- TanStack Query v5 support HOT 8
- Missing type for the returned observable in `base-query`
- Support an observable in queryFn like we had in v1 HOT 1
- Sync `mutate` function is missing the mutation options as parameter HOT 4
- Break the object reference of the result returned by the base query/mutation HOT 3
- DevTools Not Showing Queries After Updating from 2.0.0-beta.7 to 2.0.0-beta.8 HOT 2
- Cannot find module '@tanstack/query-core/build/legacy/queryClient-b7fce2ff' HOT 2
- Export MutationResult and CreateMutationOptions
- createSuccessObserverResult should also take a generic error HOT 3
- Add refetch to intersectResults HOT 6
- mutate function should subscribe to mutationObserver HOT 1
- Automatically unsubscribe query observable HOT 1
- Failure to deduplicate network requests HOT 12
- multiple fired network HOT 2
- Allow to pass observable as state keys HOT 5
- Add mapResultsData operator
- Allow constructor injection for QueryClientService HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from query.