robtaussig / react-use-websocket

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

retryOnError does not retry if share is true and shouldReconnect is not specified #209

Open dan-sherwin opened 1 year ago

dan-sherwin commented 1 year ago
    const { } = useWebSocket("wss://Imateapot.org",{
        share: true,
        retryOnError: true,
        reconnectAttempts: 3,
        reconnectInterval: 1000,
        onOpen: e=>console.log("ONOPEN", e),
        onClose: e=>console.log("ONCLOSE", e),
        onMessage: e=>console.log("ONMESSAGE", e),
        onError: e=>console.log("ONERROR", e),
        onReconnectStop: e=>console.log("ONRECONNECTSTOP", e),
    },true);

Using the example above, it will not attempt to retry the connection on connection failure. If you set share to false, it will attempt to retry the connection for the set number of attempts. If you set share to true, and specify shouldReconnect: ()=>true then it will retry the connection as well.

I would expect that it should retry the connection as my example shows, should it not?

You can test it here: CodeSandbox