-
Notifications
You must be signed in to change notification settings - Fork 58
[Feature] Tanstack/react-query package #327
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
Conversation
🦋 Changeset detectedLatest commit: 12c8abd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
a138bbf
to
5966ef0
Compare
# Conflicts: # pnpm-lock.yaml
Nice!! Having integrations with top frontend libraries will attract people from other ecosystems. Let's TanStack team know about PowerSync to list you in some places! |
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.
Looks good to me. I'm happy with this for an alpha release. Tanstack query has a very powerful and established API, this is awesome.
Ensuring that queryFn is called if custom query option is not specified.
Note: there's an issue with the base |
Minor doc improvement Co-authored-by: benitav <[email protected]>
# Conflicts: # pnpm-lock.yaml
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.
Apart from queryKey
, the useQuery
hook here looks practically the same as the normal PowerSync's useQuery
hook. What is the practical difference between the two, or where would the TanStack hook be preferred?
Briefly, the Tanstack version of So this would be valuable in cases where a project already uses Tanstack and wants to stay consistent with their APIs. Otherwise when you want to depend on some of the other query options - the caching is quite powerful. |
# Conflicts: # pnpm-lock.yaml
12c8abd
Overview
This introduces a
@powersync/tanstack-react-query
package - it contains Tanstack React Query (FKA React Query) wrapper hooks for Tanstack'suseQuery
anduseSuspenseQuery
. Piggybacking off the existing hooks for stable support for query caching and suspense.It matches the existing hooks API signature almost identically, except that
query
andparameters
options have been introduced to overwrite the existingqueryFn
option. Note thatqueryFn
is still supported, but is ignored if the newquery
option is specified in the query options.Example
The Readme covers setup and usage.
Here is example usage:
Typing
The return type of the data can be defined by
useQuery<T>
anduseQuerySuspense<T>
which means that each row returned will be of typeT
.Alternatively, compilable query support is included (with Kysely as an example):
Alternative API considered
Adding
query
andparameters
makes usage easier, especially if you consider it allows the hooks to handle compilable queries internally. An alternative would be to drop the two new options in favour of having the internals of the package simpler, and pass on deriving thequeryFn
with the SQL query and parameters (or compilable query) to somewhere else.The problem being that if we do that, there is no clear mechanism for resolving the query's dependent tables (which we need for the watch).
For example: