Skip to content

Commit ae7a70b

Browse files
authored
Merge branch 'main' into refactor/resolveValueOrFunction
2 parents 77bab27 + 0650eaf commit ae7a70b

File tree

90 files changed

+223
-163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+223
-163
lines changed

docs/framework/react/react-native.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@ useEffect(() => {
7474
## Refresh on Screen focus
7575

7676
In some situations, you may want to refetch the query when a React Native Screen is focused again.
77-
This custom hook will call the provided `refetch` function when the screen is focused again.
77+
This custom hook will refetch **all active stale queries** when the screen is focused again.
7878

7979
```tsx
8080
import React from 'react'
8181
import { useFocusEffect } from '@react-navigation/native'
82+
import { useQueryClient } from '@tanstack/react-query'
8283

83-
export function useRefreshOnFocus<T>(refetch: () => Promise<T>) {
84+
export function useRefreshOnFocus() {
85+
const queryClient = useQueryClient()
8486
const firstTimeRef = React.useRef(true)
8587

8688
useFocusEffect(
@@ -90,13 +92,18 @@ export function useRefreshOnFocus<T>(refetch: () => Promise<T>) {
9092
return
9193
}
9294

93-
refetch()
94-
}, [refetch]),
95+
// refetch all stale active queries
96+
queryClient.refetchQueries({
97+
queryKey: ['posts'],
98+
stale: true,
99+
type: 'active',
100+
})
101+
}, [queryClient]),
95102
)
96103
}
97104
```
98105

99-
In the above code, `refetch` is skipped the first time because `useFocusEffect` calls our callback on mount in addition to screen focus.
106+
In the above code, the first focus (when the screen is initially mounted) is skipped because `useFocusEffect` calls our callback on mount in addition to screen focus.
100107

101108
## Disable queries on out of focus screens
102109

docs/framework/react/reference/hydration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ hydrate(queryClient, dehydratedState, options)
9191
- `mutations: MutationOptions` The default mutation options to use for the hydrated mutations.
9292
- `queries: QueryOptions` The default query options to use for the hydrated queries.
9393
- `deserializeData?: (data: any) => any` A function to transform (deserialize) data before it is put into the cache.
94-
- `queryClient?: QueryClient`,
94+
- `queryClient?: QueryClient`
9595
- Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
9696

9797
### Limitations
@@ -122,7 +122,7 @@ function App() {
122122
- Optional
123123
- `defaultOptions: QueryOptions`
124124
- The default query options to use for the hydrated queries.
125-
- `queryClient?: QueryClient`,
125+
- `queryClient?: QueryClient`
126126
- Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
127127

128128
[//]: # 'HydrationBoundary'

docs/framework/react/reference/useIsFetching.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })
1616
**Options**
1717

1818
- `filters?: QueryFilters`: [Query Filters](../../guides/filters.md#query-filters)
19-
- `queryClient?: QueryClient`,
19+
- `queryClient?: QueryClient`
2020
- Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
2121

2222
**Returns**

docs/framework/react/reference/useIsMutating.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })
1616
**Options**
1717

1818
- `filters?: MutationFilters`: [Mutation Filters](../../guides/filters.md#mutation-filters)
19-
- `queryClient?: QueryClient`,
19+
- `queryClient?: QueryClient`
2020
- Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
2121

2222
**Returns**

docs/framework/react/reference/useMutation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ mutate(variables, {
103103

104104
**Parameter2 (QueryClient)**
105105

106-
- `queryClient?: QueryClient`,
106+
- `queryClient?: QueryClient`
107107
- Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
108108

109109
**Returns**
@@ -128,7 +128,7 @@ mutate(variables, {
128128
- If you make multiple requests, `onSuccess` will fire only after the latest call you've made.
129129
- `mutateAsync: (variables: TVariables, { onSuccess, onSettled, onError }) => Promise<TData>`
130130
- Similar to `mutate` but returns a promise which can be awaited.
131-
- `status: string`
131+
- `status: MutationStatus`
132132
- Will be:
133133
- `idle` initial status prior to the mutation function executing.
134134
- `pending` if the mutation is currently executing.

docs/framework/react/reference/useMutationState.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const latest = data[data.length - 1]
7272
- `filters?: MutationFilters`: [Mutation Filters](../../guides/filters.md#mutation-filters)
7373
- `select?: (mutation: Mutation) => TResult`
7474
- Use this to transform the mutation state.
75-
- `queryClient?: QueryClient`,
75+
- `queryClient?: QueryClient`
7676
- Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
7777

7878
**Returns**

docs/framework/react/reference/useQuery.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const {
9191
- This function receives a `retryAttempt` integer and the actual Error and returns the delay to apply before the next attempt in milliseconds.
9292
- A function like `attempt => Math.min(attempt > 1 ? 2 ** attempt * 1000 : 1000, 30 * 1000)` applies exponential backoff.
9393
- A function like `attempt => attempt * 1000` applies linear backoff.
94-
- `staleTime: number | 'static' ((query: Query) => number | 'static')`
94+
- `staleTime: number | 'static' | ((query: Query) => number | 'static')`
9595
- Optional
9696
- Defaults to `0`
9797
- The time in milliseconds after which data is considered stale. This value only applies to the hook it is defined on.
@@ -154,12 +154,12 @@ const {
154154
- `initialDataUpdatedAt: number | (() => number | undefined)`
155155
- Optional
156156
- If set, this value will be used as the time (in milliseconds) of when the `initialData` itself was last updated.
157-
- `placeholderData: TData | (previousValue: TData | undefined; previousQuery: Query | undefined,) => TData`
157+
- `placeholderData: TData | (previousValue: TData | undefined, previousQuery: Query | undefined) => TData`
158158
- Optional
159159
- If set, this value will be used as the placeholder data for this particular query observer while the query is still in the `pending` state.
160160
- `placeholderData` is **not persisted** to the cache
161161
- If you provide a function for `placeholderData`, as a first argument you will receive previously watched query data if available, and the second argument will be the complete previousQuery instance.
162-
- `structuralSharing: boolean | (oldData: unknown | undefined, newData: unknown) => unknown)`
162+
- `structuralSharing: boolean | (oldData: unknown | undefined, newData: unknown) => unknown`
163163
- Optional
164164
- Defaults to `true`
165165
- If set to `false`, structural sharing between query results will be disabled.
@@ -178,7 +178,7 @@ const {
178178

179179
**Parameter2 (QueryClient)**
180180

181-
- `queryClient?: QueryClient`,
181+
- `queryClient?: QueryClient`
182182
- Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
183183

184184
**Returns**

docs/framework/react/reference/useQueryClient.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ const queryClient = useQueryClient(queryClient?: QueryClient)
1313

1414
**Options**
1515

16-
- `queryClient?: QueryClient`,
16+
- `queryClient?: QueryClient`
1717
- Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.

docs/framework/react/typescript.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ function groupMutationOptions() {
250250
}
251251

252252
useMutation({
253-
...groupMutationOptions()
254-
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['groups'] })
253+
...groupMutationOptions(),
254+
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['groups'] }),
255255
})
256256
useIsMutating(groupMutationOptions())
257257
queryClient.isMutating(groupMutationOptions())

examples/angular/auto-refetching/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"@angular/compiler": "^20.0.0",
1414
"@angular/core": "^20.0.0",
1515
"@angular/platform-browser": "^20.0.0",
16-
"@tanstack/angular-query-experimental": "^5.85.5",
16+
"@tanstack/angular-query-experimental": "^5.85.6",
1717
"rxjs": "^7.8.2",
1818
"tslib": "^2.8.1",
1919
"zone.js": "0.15.0"

0 commit comments

Comments
 (0)