react-use-websocket
react-use-websocket copied to clipboard
Connection persists on closed tab
Hey, thanks for the awesome lib. I have a question however, is the socket supposed to not close when I close the tab ?
Hi @poljsakerik ,
When you say 'tab', do you mean browser tab? If so, the browser is supposed to handle this for you (afaik), but there is no reliable way to back this up on the client-side (this library only closes the websockets based on when your components unmount, which will not get triggered if the window is suddenly terminated). I'd recommend setting up a heartbeat/ping-pong system, which will close the connection on the server-side if the client doesn't respond in a timely manner.