robtaussig / react-use-websocket

React Hook for WebSocket communication
MIT License
1.55k stars 135 forks source link

How do you disconnect when the react page refeshes? #218

Closed sleh96 closed 6 months ago

sleh96 commented 10 months ago

I apologize if this is a duplicate, but I have looked for this issue in the open issues or pull requests but I could not find anything helpful. So my question is how do you disconnect a websocket client using this hook?

lucasalmeida92 commented 10 months ago

I think you have to do this: getWebSocket().close()

danielmcmillan commented 7 months ago

The third parameter to useWebSocket is connect, you can set it to false to disable the connection. Or set url to null. Not sure what you mean by "when the react page refeshes", it should disconnect automatically when the component unmounts.