Skip to content

fix(react-query): allow passing options to useQuery without initialData #3873

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

Merged
merged 5 commits into from
Jul 21, 2022

Conversation

juanhenriquez
Copy link

@juanhenriquez juanhenriquez commented Jul 19, 2022

On react-query v3, users were allowed to pass custom options to useQuery and useInfiniteQuery without needing of passing initialData.

function useQueryPosts(isAdmin, options?: UseQueryOptions<number, Error, number>) {
  return useQuery<number, Error, number>(["posts"], () => 10, {
    enabled: isAdmin,
    ...options
  });
}

With the launch of react-query v4, this is not possible anymore as all the overload functions of useQuery forces the user to pass initialData:

function useQueryPosts(isAdmin, options?: UseQueryOptions<number, Error, number>) {
  return useQuery<number, Error, number>(["posts"], () => 10, {
    enabled: isAdmin,
    initialData: () => null,
    ...options
  });
}

So, this Pull Request adds a new overload function which allow users to pass options without forcing them to pass initialData (as it was on v3).

@vercel
Copy link

vercel bot commented Jul 19, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
query ❌ Failed (Inspect) Jul 20, 2022 at 5:42PM (UTC)

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 20, 2022

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 1d3b9ec:

Sandbox Source
@tanstack/query-example-react-basic Configuration
@tanstack/query-example-react-basic-typescript Configuration

@codecov-commenter
Copy link

Codecov Report

Merging #3873 (1d3b9ec) into main (eab6e2c) will increase coverage by 0.41%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #3873      +/-   ##
==========================================
+ Coverage   96.36%   96.77%   +0.41%     
==========================================
  Files          45       57      +12     
  Lines        2281     2668     +387     
  Branches      640      784     +144     
==========================================
+ Hits         2198     2582     +384     
- Misses         80       84       +4     
+ Partials        3        2       -1     
Impacted Files Coverage Δ
src/react/useQueries.ts
src/core/infiniteQueryBehavior.ts
src/devtools/tests/utils.tsx
src/core/subscribable.ts
src/devtools/styledComponents.ts
src/core/infiniteQueryObserver.ts
src/devtools/theme.tsx
...rc/createWebStoragePersistor-experimental/index.ts
src/core/mutationObserver.ts
src/react/QueryClientProvider.tsx
... and 92 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9537fe9...1d3b9ec. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants