Skip to content

Conversation

simolus3
Copy link
Contributor

@simolus3 simolus3 commented Sep 15, 2025

This updates the react package to expose hooks for sync streams:

  • The useSyncStream() hook has been added. It takes name and parameters of the stream, along with optional subscription options. When called, it:
    • creates a stream subscription on the requested stream
    • returns the current subscription state of that stream subscription
    • unsubscribes when the component is unmounted
  • The useQuery() hook has been updated to optionally take an array of streams as well.
    • Similarly to useSyncStream(), it subscribes to those streams while the component is active.
    • Additionally, it delays the queries until the subscriptions have been synced at least once. This is a neat shortcut to display a loading state while data is downloading / querying from the database and then transition to data once it's available.

I've also fixed a few minor issues with the sync stream implementation in this PR.

Copy link

changeset-bot bot commented Sep 15, 2025

🦋 Changeset detected

Latest commit: c694022

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@powersync/react-native Minor
@powersync/common Minor
@powersync/web Minor
@powersync/node Minor
@powersync/react Minor
@powersync/adapter-sql-js Patch
@powersync/op-sqlite Patch
@powersync/tanstack-react-query Patch
@powersync/diagnostics-app Patch

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

Base automatically changed from sync-streams to main September 17, 2025 09:29
@simolus3 simolus3 marked this pull request as ready for review September 17, 2025 15:35
stevensJourney
stevensJourney previously approved these changes Sep 22, 2025
Copy link
Collaborator

@stevensJourney stevensJourney left a comment

Choose a reason for hiding this comment

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

Happy with the changes :)

Copy link
Collaborator

@stevensJourney stevensJourney left a comment

Choose a reason for hiding this comment

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

🚀 This is very cool

@simolus3 simolus3 merged commit 7a5aaf5 into main Sep 23, 2025
9 of 15 checks passed
@simolus3 simolus3 deleted the sync-stream-hooks branch September 23, 2025 08:42
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