Skip to content

Commit 3fd3460

Browse files
authored
docs(react): clarify staleTime 'static' vs Infinity with 'always' triggers (#10354)
* docs(react): clarify staleTime 'static' vs Infinity with 'always' triggers * docs(react): lead with invalidateQueries() distinction for staleTime: 'static' vs Infinity
1 parent 73e783b commit 3fd3460

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

docs/framework/react/guides/important-defaults.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Out of the box, TanStack Query is configured with **aggressive but sane** defaul
1414
- set `staleTime` to `Infinity` to never trigger a refetch until the Query is [invalidated manually](./query-invalidation.md).
1515
- set `staleTime` to `'static'` to **never** trigger a refetch, even if the Query is [invalidated manually](./query-invalidation.md).
1616

17+
> `'static'` and `Infinity` both prevent staleness-based refetches, but `'static'` is stricter: `queryClient.invalidateQueries()` can invalidate a query with `staleTime: Infinity`, but has no effect on `staleTime: 'static'`. `refetchOnMount`, `refetchOnWindowFocus`, and `refetchOnReconnect` set to `"always"` are also blocked by `'static'`. Use `'static'` for data that cannot change while the app is running: feature flags fetched at boot, user permissions loaded at login, static reference tables. Use `Infinity` when you still want manual invalidation to work.
18+
1719
- Stale queries are refetched automatically in the background when:
1820
- New instances of the query mount
1921
- The window is refocused

0 commit comments

Comments
 (0)