T
TanStack11mo ago
rare-sapphire

RQ frequent cache updates using WebSockets

Hey everyone, I’m working on a React chat app and using React Query for data. Basically, I fetch the conversations list and messages from two separate APIs at first, but after that, all interactions (like new messages, unread counts, etc.) are handled through WebSockets (inbound and outbound). Right now, I’m using setQueryData to update the React Query cache whenever a WebSocket event happens so the UI updates immediately (like appending messages or updating the last message in a conversation). It works, but I’m wondering if this is the best approach? It feels like it might get slow or messy with a lot of updates. Is there a better way to handle frequent WebSocket updates with React Query?
1 Reply
secure-lavender
secure-lavender11mo ago
This is rather a generic react optimization question, if things get too bad, you can always implement a buffer system, where you store the events and only handle UI updates every x milliseconds Essentially batching events

Did you find this page helpful?