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

[UI v2] feat: Use queryOptions API to define queries #16133

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

devinvillarosa
Copy link
Contributor

@devinvillarosa devinvillarosa commented Nov 27, 2024

What does this PR do and why?

This PR wraps queryKey and queryFn objects using the queryOptions API.
Opting to use the queryOptions wrapper due to its Typescript benefits (see attachment).
Additionally, all tanstack router + query uses queryOptions in their latest documentation examples

Overall, by using the queryOptions wrapper, our codebase knows what the expected return type is based on the query keys provided in the queryClient

And a good blog read: https://tkdodo.eu/blog/the-query-options-api

(Without the wrapper, TS assumes any type that is associated with the provided queryKey. With the wrapper, TS magically 🧙 knows what the expected type is for this cache)

Screen.Recording.2024-11-27.at.9.19.29.AM.mov

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
    • If no issue exists and your change is not a small fix, please create an issue first.
  • If this pull request adds new functionality, it includes unit tests that cover the changes
  • If this pull request removes docs files, it includes redirect settings in mint.json.
  • If this pull request adds functions or classes, it includes helpful docstrings.

Related to #15512

@devinvillarosa devinvillarosa marked this pull request as ready for review November 27, 2024 17:32
Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devinvillarosa devinvillarosa merged commit c1c70c2 into main Nov 27, 2024
19 checks passed
@devinvillarosa devinvillarosa deleted the query-options-for-variables branch November 27, 2024 17:44
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.

2 participants