What is best practice to websocket reconnect in react?
Wrap WebSocket connection and onmessage in a function. check if WebSocket is close, callback the function. Also may use setTimeout. Example :
function connect(){
//WebSocket Connection
//WebSocket onmessage
}
conn.onclose = evt => {
console.log('Socket is closed.Reconnect will be attempted in 10 second.', evt.reason);
setTimeout(() => connect(), 10000);
};