Feedback on useQueryStream Hook for Observable Integration with React Query
I’m reaching out for some guidance to validate an idea we’ve been tinkering with—creating a custom hook called useQueryStream to handle Observables with React Query. We know you’ve mentioned before that streaming data flows aren’t officially supported, but we think our situation might be a bit different, and we’d love to get your take on it.
We’d really appreciate any feedback you can give us on this approach.
Thanks
Marco
There is a longer version in github 🙂 at https://github.com/TanStack/query/discussions/7581.
Demo at https://codesandbox.io/p/sandbox/use-subscription-query-83d72d?file=%2Fsrc%2Fgrid-stream.tsx%3A5%2C2-8%2C6
The main idea is to create a StreamQueryObserver with a streamQueryBehavior and create a hook that uses useBaseQuery under the hood.
Usage:
const { data, isLoading } = useQueryStream({
queryKey: ["grid-stream", queryKey],
queryFn: mySseImplementation,
});
0 Replies