Comments (2)
the options do update on the query, but not on the retry. Let me explain:
when a query starts to run, we create an internal retryer
and pass options from the query to it:
query/packages/query-core/src/query.ts
Lines 527 to 529 in 7368bd0
Then, that retryer takes those options, returns a promise and will resolve or reject it once the whole process of fetching is complete. This takes retries, network availability etc. into account. Fore example, the query might go into paused
state in between and continue with retries later.
So the retryer will see the options from the time it was created (=when the fetch started). Usually, this is what you want because the retry process is opaque. The promise will resolve or reject eventually, and then, when a refetch
occurs (which is different from a retry
), the new values will be respected.
We could make those values reactive in between retries, but I think that'll open up a can of worms. What if you change retries from 5
to 2
while you are at the 3rd retry? What if you change networkMode
to 'always'
while the query is paused
because you have no network connection? It's the safer approach to just trigger the whole process (fetch + retries) with a given set of options from creation time until it is finished. It's a bit how closures work with react functions, too.
Both retry
and retryDelay
can be a function, so you can define them as a function and use a ref
to read the latest value inside of it if you really want.
from query.
I had the same issue trying to update a variable inside useQuery
whitout updating the queryKey
useQuery will only update the variables within it if the queryKey
is changed. As it stands, even changing the retryDelay the query will not have its values โโupdated, since the queryKey
has not changed
If you change line 12 to this one you will see that the problem has been solved
queryKey: ['test', retryDelay],
refetchInterval
is used to revalidate the query, so it will only work if it is successful.
I think that it happens because of the caching in react-query. The function will not update is own values if the key doesn't change, it will only update the data.
Maybe I'm making a mistake trying to prove you my point (I've heard it while a go, so that is the reason that I know it), but maybe the useQuery
component will only trigger the useEffect
and rerender it state when some of the options in queryKey, queryFn changes.
https://github.com/TanStack/query/blob/main/packages/react-query/src/useBaseQuery.ts#L91
from query.
Related Issues (20)
- Docs website doesn't work in Brave HOT 2
- Docs website is down HOT 3
- Docs: Error on migration guides HOT 1
- queryFn with server action name not working on Next.js
- isLoading does not exist on useMutation @tanstack/vue-query
- Docs: Invalid links in quick-start.md
- Query not updating when Set used in query key HOT 1
- Vue Query + Nuxt 3 SSG - Can not reset hydrated query HOT 2
- Entire website is down HOT 1
- eslint plugin: false positive for function calls HOT 4
- queryOptions should to pass initialData with a callback that is potentially returning undefined HOT 9
- The query status does not change when the query is activated after being inactive despite executing queryFn HOT 1
- Allow to pass nonce to ReactQueryStreamedHydration HOT 1
- TypeError: Cannot assign to read only property '0' of object '[object Array]' HOT 2
- In the underlying code, pages in the getNextPageParam method in infiniteQueryBehavior is undefined. HOT 1
- pages in the getNextPageParam method in infiniteQueryBehavior is undefined. HOT 3
- [Vue]: skipToken example is misleading
- queryOptions is not in @tanstack/react-query HOT 1
- Handling Offline Mutations Persistently Across App Restarts in React Query v5 HOT 2
- eslint-plugin-query: @tanstack/query/exhaustive-deps is triggered for a type used in an instanceof call. HOT 2
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.