useSWRSubscription With WebSocket: Possibility To Send Data #2813
Unanswered
piet-maier
asked this question in
Ideas
Replies: 1 comment
-
Any leads on this? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First off: Please correct me if I am completely wrong and it is already possible to use the
useSWRSubscription
hook with a web socket and send data back to the server. As far as I can tell this is not the case.I know that the point of the
swr
package is to fetch data, and not to send it. However, when offering a hook that can be used to handle a web socket connection, I find it somewhat weird that the user does not have the possibility to also send data back to the server, which arguably is half of what web sockets are about.My proposal would therefore be: In the same or a similar way that the hook accepts a function to establish the connection and attach event listeners for incoming messages, it should provide a possibility to send messages. The simplest way would be exposing the socket itself, so that the user can call
send
on it.One could, of course, store the socket in an external variable when first creating it, but I do not think that is an ideal solution, if only because that means creating multiple references to it.
Beta Was this translation helpful? Give feedback.
All reactions