Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc(queryClient): add dev warning with queryDefaults #3249

Merged
merged 16 commits into from
Feb 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
doc(QueryClient): fix link to documentation
Guillaume Labat committed Jan 31, 2022
commit 8c43779317ffb804071b79e53afc000fad6bcb08
6 changes: 3 additions & 3 deletions docs/src/pages/reference/QueryClient.md
Original file line number Diff line number Diff line change
@@ -476,7 +476,7 @@ const defaultOptions = queryClient.getQueryDefaults(['posts'])
```

> Note that if several query defaults match the given query key, the **first** matching one is returned.
> This could lead to unexpected behaviours. See [`setquerydefaults`](#queryclientsetquerydefaults).
> This could lead to unexpected behaviours. See [`setQueryDefaults`](#queryclientsetquerydefaults).

## `queryClient.setQueryDefaults`

@@ -495,8 +495,8 @@ function Component() {
- `queryKey: QueryKey`: [Query Keys](../guides/query-keys)
- `options: QueryOptions`

> As stated in [`getquerydefaults`](#queryclientgetquerydefaults), the order of registration of query defaults does matter.
> Since the **first** matching defaults are returned by `getquerydefaults`, the registration should be made in the following order: from the **least generic key** to the **most generic one**. This way, in case of specific key, the first matching one would be the expected one.
> As stated in [`getQueryDefaults`](#queryclientgetquerydefaults), the order of registration of query defaults does matter.
> Since the **first** matching defaults are returned by `getQueryDefaults`, the registration should be made in the following order: from the **least generic key** to the **most generic one**. This way, in case of specific key, the first matching one would be the expected one.

## `queryClient.getMutationDefaults`

6 changes: 3 additions & 3 deletions src/core/queryClient.ts
Original file line number Diff line number Diff line change
@@ -532,7 +532,7 @@ export class QueryClient {
}
}

findQueryDefaults(
findFirstMatchingQueryDefaults(
queryKey?: QueryKey
): QueryOptions<any, any, any> | undefined {
if (!queryKey) {
@@ -548,7 +548,7 @@ export class QueryClient {
console.warn(
`[QueryClient] Several defaults match with key '${JSON.stringify(
queryKey
)}'. The first matching query options are used. Please check how query defaults are registered. Order does matter here. cf. http://react-query.com/some/link/to/document#queryDefaults.`
)}'. The first matching query defaults are used. Please check how query defaults are registered. Order does matter here. cf. https://react-query.tanstack.com/reference/QueryClient#queryclientsetquerydefaults.`
)
}
// Explicitly returns the first one
@@ -559,7 +559,7 @@ export class QueryClient {
getQueryDefaults(
GLabat marked this conversation as resolved.
Show resolved Hide resolved
queryKey?: QueryKey
): QueryObserverOptions<any, any, any, any, any> | undefined {
const queryDefaults = this.findQueryDefaults(queryKey)
const queryDefaults = this.findFirstMatchingQueryDefaults(queryKey)
return queryDefaults
}