Hacker News new | ask | show | jobs
by notrab 1248 days ago
The purpose of the `@live` query is that it uses server-sent events to update the client state with any new changes that happen on the server. It's correct that you can use something like Tanstack Query, useSWR, React Apollo, or even fetch to poll the server again but that requires fetching all of the data that was previously fetched to update the client state. Instead with SSE, you get a diff in the format of JSON Patch that you can use to apply any changes to the current state without refetching everything.

There are many implementations of Live Queries (some that just use polling under the hood) but we really like the concept of using JSON Patch with SSE.

1 comments

I should add that using regular queries with Apollo, URQL, etc. is perfectly fine. If you're building an app that requires realtime data then `@live` queries can be really useful. The data can update in realtime without refreshing and there's no need for WebSockets!

There are limitations to server-sent events, but `@live` queries is a perfect fit imo.