Using SWR with HTTP long-polling #1856
-
Hello, new to SWR (and React, really), anyway, it seems like a great way to do 'fetchy' stuff in React. I have a server-side application which implements API updates via HTTP long-polling. Long polling is simply where the server doesn't respond to the HTTP request until new-data or an update is available. I'm wondering if there are examples of using SWR with long-polling???? It seems I could use SWR with a very small polling interval, ie Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello there! Unfortunately SWR doesn't have a built-in way to handle long-polling. Using I think it makes sense to think about a good way to support long-polling in SWR, perhaps with #1263 (but that would still require some code to setup, this is something we need to have in mind when designing this new API). Fundamentally long-polling is something more similar to subscription than fetch: single instance, always connected and deduplicates others. |
Beta Was this translation helpful? Give feedback.
Hello there!
Unfortunately SWR doesn't have a built-in way to handle long-polling. Using
refreshInterval: 1
is a good work around indeed.I think it makes sense to think about a good way to support long-polling in SWR, perhaps with #1263 (but that would still require some code to setup, this is something we need to have in mind when designing this new API). Fundamentally long-polling is something more similar to subscription than fetch: single instance, always connected and deduplicates others.