Generateurv2/frontend/hooks/useReconnecting.jsx
2022-05-18 10:15:54 +02:00

22 lines
567 B
JavaScript

import { useEffect, useState } from "react";
import { isBrowser } from "../utils/utils.js";
export default function useReconnecting(ws, url, connect, id_code) {
const [tried, setTried] = useState(false)
useEffect(() => {
if (ws == null) {
connect(url);
setTried(true);
//router.push({ pathname: "/room/join" });
} else if (ws != null && tried && isBrowser) {
ws.send(
JSON.stringify({
data: {
type: "reconnect",
clientId: clientId,
},
})
);
}
}, [tried]);
}