Open History to see the last commit
1---
2id: important-defaults
3title: Important Defaults
4---
5β
6Out of the box, TanStack Query is configured with **aggressive but sane** defaults. **Sometimes these defaults can catch new users off guard or make learning/debugging difficult if they are unknown by the user.** Keep them in mind as you continue to learn and use TanStack Query:
7β
8- Query instances via `useQuery` or `useInfiniteQuery` by default **consider cached data as stale**.
9β
10> To change this behavior, you can configure your queries both globally and per-query using the `staleTime` option. Specifying a longer `staleTime` means queries will not refetch their data as often
11β
12- Stale queries are refetched automatically in the background when:
13 - New instances of the query mount
14 - The window is refocused
15 - The network is reconnected
16 - The query is optionally configured with a refetch interval
17β
18If you see a refetch that you are not expecting, it is likely because you just focused the window and TanStack Query is doing a [`refetchOnWindowFocus`](../guides/window-focus-refetching). During development, this will probably be triggered more frequently, especially because focusing between the Browser DevTools and your app will also cause a fetch, so be aware of that.
19β
20> To change this functionality, you can use options like `refetchOnMount`, `refetchOnWindowFocus`, `refetchOnReconnect` and `refetchInterval`.
21β
22- Query results that have no more active instances of `useQuery`, `useInfiniteQuery` or query observers are labeled as "inactive" and remain in the cache in case they are used again at a later time.
23- By default, "inactive" queries are garbage collected after **5 minutes**.
24β
25 > To change this, you can alter the default `cacheTime` for queries to something other than `1000 * 60 * 5` milliseconds.
26β
27- Queries that fail are **silently retried 3 times, with exponential backoff delay** before capturing and displaying an error to the UI.
28β
29 > To change this, you can alter the default `retry` and `retryDelay` options for queries to something other than `3` and the default exponential backoff function.
30β
31- Query results by default are **structurally shared to detect if data has actually changed** and if not, **the data reference remains unchanged** to better help with value stabilization with regards to useMemo and useCallback. If this concept sounds foreign, then don't worry about it! 99.9% of the time you will not need to disable this and it makes your app more performant at zero cost to you.
32β
33 > Structural sharing only works with JSON-compatible values, any other value types will always be considered as changed. If you are seeing performance issues because of large responses for example, you can disable this feature with the `config.structuralSharing` flag. If you are dealing with non-JSON compatible values in your query responses and still want to detect if data has changed or not, you can define a data compare function with `config.isDataEqual` or provide your own custom function as `config.structuralSharing` to compute a value from the old and new responses, retaining references as required.
34β
35[//]: # 'Materials'
36β
37## Further Reading
38β
39Have a look at the following articles from our Community Resources for further explanations of the defaults:
40β
41- [Practical React Query](../community/tkdodos-blog#1-practical-react-query)
42- [React Query as a State Manager](../community/tkdodos-blog#10-react-query-as-a-state-manager)
43β
44[//]: # 'Materials'