-
Notifications
You must be signed in to change notification settings - Fork 577
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
RJS-2649: Add more additional overload to useQuery to allow exhaustive-deps to work #6819
Conversation
packages/realm-react/package.json
Outdated
"name": "@hernas/realm-react", | ||
"version": "0.9.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert these 🙂
Very interesting approach - I'd be happy to merge this, although this hook is turning into a bit of an overload nightmare 🙈 |
@kraenhansen Updated. Not sure why my Crossing my fingers to have this change on next release, we will finally be able to use official package rather than our fork 👍 |
/* eslint-disable-next-line react-hooks/rules-of-hooks -- We're calling `useQuery` once in any of the brances */ | ||
return useQuery(typeOrOptions, Array.isArray(queryOrDeps) ? queryOrDeps : deps); | ||
return useQuery( | ||
{ ...(depsOrPartialOptions as QuaryHookPartialOptions<T>), query: typeOrOptionsOrQuery as QueryCallback<T> }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to write this using a type assert function instead? I.e. something which test the value and return : assert arg is QueryHookPartialOptions<T>
instead of using the as QueryHookPartialOptions<T>
?
@@ -31,6 +31,8 @@ export type QueryHookOptions<T> = { | |||
keyPaths?: string | string[]; | |||
}; | |||
|
|||
export type QuaryHookPartialOptions<T> = Omit<QueryHookOptions<T>, "query">; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A small typo:
export type QuaryHookPartialOptions<T> = Omit<QueryHookOptions<T>, "query">; | |
export type QueryHookPartialOptions<T> = Omit<QueryHookOptions<T>, "query">; |
I wonder if it would be easier to declare a base type (without the query
) and declare QueryHookOptions<T>
as a union with that base type and { query: ... }
?
@kraenhansen Typeguards were a good suggestion. I went further and refactored the code quite a bit to make it more readable. |
Just did a quick read through ... and I like it! 💙 It reads much better now. Thanks a lot! |
@kraenhansen Is there a timeline for when is this going to be merged? We would love to switch from fork to official realm react package. |
This was just published as |
What, How & Why?
Related to #6284