TanStackT
TanStack2mo ago
6 replies
wet-aqua

On-demand sync with streaming/SSE

Is there a way to use query-driven sync with on-demand mode and stream in changes through SSE?
I am using trpc with SSE and connected it to Tanstack DB through manually inserting new data/changes into a localOnlyCollection in the useSubscription hook (Tanstack Query):
 useSubscription(
    trpc.myEndpoint.onSegmentChange.subscriptionOptions(
      { segmentId, languageId },
      {
        onData(data) {           
          if (data.data.type === "initial") {
            for (const exhibit of data.data.exhibits) {
              auctionExhibitsCollection.insert(exhibit);
            }
          } else if (data.data.type === "update") {
            for (const exhibit of data.data.exhibits) {
              auctionExhibitsCollection.update(exhibit.id, (draft) => {
                draft.someProperty = exhibit.someProperty;                 
              });
            }
          }
        },
      },
    )


This works but I wonder if I could use query-driven sync here to let the query decide on the parameters (like segmentId or languageId in my case).
Was this page helpful?