Skip to content

Commit 37a3118

Browse files
authored
Merge pull request #4 from tannerlinsley/master
update
2 parents e29ae76 + 64dec9e commit 37a3118

File tree

17 files changed

+80
-32
lines changed

17 files changed

+80
-32
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
],
3030
"no-shadow": "error",
3131
"import/no-cycle": "error",
32-
"import/no-unresolved": "error",
32+
"import/no-unresolved": ["error", { "ignore": ["react-query"] }],
3333
"import/no-unused-modules": ["off", { "unusedExports": true }],
3434
"no-redeclare": "off"
3535
}

docs/src/pages/guides/migrating-to-react-query-3.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const queryClient = new QueryClient()
4848

4949
Default options for queries and mutations can now be specified in `QueryClient`:
5050

51+
**Notice that it's now defaultOptions instead of defaultConfig**
52+
5153
```js
5254
const queryClient = new QueryClient({
5355
defaultOptions: {
@@ -147,7 +149,7 @@ They were previously added as the last query key parameter in your query functio
147149
useInfiniteQuery(['posts'], (_key, pageParam = 0) => fetchPosts(pageParam))
148150

149151
// New
150-
useInfiniteQuery(['posts'], ({ pageParam = 0 }) => fetchPost(pageParam))
152+
useInfiniteQuery(['posts'], ({ pageParam = 0 }) => fetchPosts(pageParam))
151153
```
152154

153155
### usePaginatedQuery() has been deprecated in favor of the `keepPreviousData` option

docs/src/pages/guides/mutations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ In the example above, you also saw that you can pass variables to your mutations
5353

5454
Even with just variables, mutations aren't all that special, but when used with the `onSuccess` option, the [Query Client's `invalidateQueries` method](../reference/QueryClient#queryclientinvalidatequeries) and the [Query Client's `setQueryData` method](../reference/QueryClient#queryclientsetquerydata), mutations become a very powerful tool.
5555

56-
> IMPORTANT: The `mutate` function is an asynchronous function, which means you cannot use it directly in an event callback. If you need to access the event in `onSubmit` you need to wrap `mutate` in another function. This is due to [React event pooling](https://reactjs.org/docs/events.html#event-pooling).
56+
> IMPORTANT: The `mutate` function is an asynchronous function, which means you cannot use it directly in an event callback in **React 16 and earlier**. If you need to access the event in `onSubmit` you need to wrap `mutate` in another function. This is due to [React event pooling](https://reactjs.org/docs/legacy-event-pooling.html).
5757
5858
```js
59-
// This will not work
59+
// This will not work in React 16 and earlier
6060
const CreateTodo = () => {
6161
const mutation = useMutation(event => {
6262
event.preventDefault()

docs/src/pages/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Once you grasp the nature of server state in your application, **even more chall
2020

2121
- Caching... (possibly the hardest thing to do in programming)
2222
- Deduping multiple requests for the same data into a single request
23-
- Updating out of date data in the background
23+
- Updating "out of date" data in the background
2424
- Knowing when data is "out of date"
2525
- Reflecting updates to data as quickly as possible
2626
- Performance optimizations like pagination and lazy loading data

docs/src/pages/reference/useQuery.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ const result = useQuery({
8989
- A function like `attempt => Math.min(attempt > 1 ? 2 ** attempt * 1000 : 1000, 30 * 1000)` applies exponential backoff.
9090
- A function like `attempt => attempt * 1000` applies linear backoff.
9191
- `staleTime: number | Infinity`
92+
- Optional
93+
- Defaults to `0`
9294
- The time in milliseconds after data is considered stale. This value only applies to the hook it is defined on.
9395
- If set to `Infinity`, the data will never be considered stale
9496
- `cacheTime: number | Infinity`
@@ -168,6 +170,9 @@ const result = useQuery({
168170
- Optional
169171
- Defaults to `true`
170172
- If set to `false`, structural sharing between query results will be disabled.
173+
- `useErrorBoundary: boolean`
174+
- Defaults to the global query config's `useErrorBoundary` value, which is false
175+
- Set this to true if you want errors to be thrown in the render phase and propagated to the nearest error boundary
171176
172177
**Returns**
173178

rollup.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import commonJS from 'rollup-plugin-commonjs'
77
import visualizer from 'rollup-plugin-visualizer'
88
import replace from '@rollup/plugin-replace'
99

10-
const external = ['react', 'react-dom']
10+
const external = ['react', 'react-dom', 'react-query']
1111

1212
const globals = {
1313
react: 'React',
1414
'react-dom': 'ReactDOM',
15+
'react-query': 'ReactQuery',
1516
}
1617

1718
const inputSrcs = [

src/core/infiniteQueryObserver.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ export class InfiniteQueryObserver<
7575
})
7676
}
7777

78+
getOptimisticResult(
79+
options: InfiniteQueryObserverOptions<
80+
TQueryFnData,
81+
TError,
82+
TData,
83+
TQueryData
84+
>
85+
): InfiniteQueryObserverResult<TData, TError> {
86+
options.behavior = infiniteQueryBehavior()
87+
return super.getOptimisticResult(options) as InfiniteQueryObserverResult<
88+
TData,
89+
TError
90+
>
91+
}
92+
7893
fetchNextPage(
7994
options?: FetchNextPageOptions
8095
): Promise<InfiniteQueryObserverResult<TData, TError>> {

src/core/query.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
Updater,
3-
ensureArray,
43
functionalUpdate,
54
isValidTimeout,
65
noop,
@@ -378,9 +377,8 @@ export class Query<
378377
}
379378

380379
// Create query function context
381-
const queryKey = ensureArray(this.queryKey)
382-
const queryFnContext: QueryFunctionContext<unknown[]> = {
383-
queryKey,
380+
const queryFnContext: QueryFunctionContext<TQueryKey> = {
381+
queryKey: this.queryKey,
384382
pageParam: undefined,
385383
}
386384

@@ -394,7 +392,7 @@ export class Query<
394392
const context: FetchContext<TQueryFnData, TError, TData, any> = {
395393
fetchOptions,
396394
options: this.options,
397-
queryKey,
395+
queryKey: this.queryKey,
398396
state: this.state,
399397
fetchFn,
400398
}

src/core/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export interface QueryOptions<
5959
retryDelay?: RetryDelayValue<TError>
6060
cacheTime?: number
6161
isDataEqual?: (oldData: TData | undefined, newData: TData) => boolean
62-
queryFn?: QueryFunction<TQueryFnData>
62+
queryFn?: QueryFunction<TQueryFnData, TQueryKey>
6363
queryHash?: string
6464
queryKey?: TQueryKey
6565
queryKeyHashFn?: QueryKeyHashFunction<TQueryKey>

src/devtools/devtools.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// @ts-nocheck
22

33
import React from 'react'
4+
5+
import { useQueryClient } from 'react-query'
46
import { matchSorter } from 'match-sorter'
5-
import { useQueryClient } from '../react'
67
import useLocalStorage from './useLocalStorage'
7-
import { useSafeState, isStale } from './utils'
8+
import { useSafeState } from './utils'
89

910
import {
1011
Panel,
@@ -305,7 +306,7 @@ export function ReactQueryDevtools({
305306
}
306307

307308
const getStatusRank = q =>
308-
q.state.isFetching ? 0 : !q.observers.length ? 3 : isStale(q) ? 2 : 1
309+
q.state.isFetching ? 0 : !q.observers.length ? 3 : q.isStale() ? 2 : 1
309310

310311
const sortFns = {
311312
'Status > Last Updated': (a, b) =>

0 commit comments

Comments
 (0)