Skip to content

Conversation

@fnune
Copy link
Contributor

@fnune fnune commented May 28, 2021

I noticed my default staleTime wasn't applying after I introduced a utility to namespace query keys. This was because I'd assumed setDefaultOptions would merge with previously-defined defaults, but it doesn't.

I fixed this in my project by merging with a default config object:

+ import { merge } from "lodash";

And then:

- queryClient.setDefaultOptions({
-     queries: {
-         queryKeyHashFn: myFunction,
-     },
- });
+ queryClient.setDefaultOptions(
+     merge<DefaultOptions, DefaultOptions>(
+         {
+             queries: {
+                 queryKeyHashFn: myFunction,
+             },
+         },
+         DEFAULT_QUERY_CLIENT_OPTIONS
+     )
+ );

I'm opening this PR to discuss mentioning this behavior in the docs. Additionally, setDefaultOptions could take a function where the existing options get passed.

@vercel
Copy link

vercel bot commented May 28, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/tannerlinsley/react-query/A6ZKKzv5w9FuoEvX7w3V3GKsD8o4
✅ Preview: https://react-query-git-fork-fnune-document-that-set-default-fb07f5.vercel.app

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 9a6faa4:

Sandbox Source
tannerlinsley/react-query: basic Configuration
tannerlinsley/react-query: basic-typescript Configuration

@TkDodo TkDodo merged commit 85d14d3 into TanStack:master May 30, 2021
@tannerlinsley
Copy link
Member

🎉 This PR is included in version 3.16.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants