fix websocket

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-07-17 23:36:41 +02:00
parent f0a2cafa74
commit a2cf2ee564
4 changed files with 18 additions and 26 deletions

View File

@@ -24,10 +24,13 @@ export default function useWS<T>(
.replace(/^http/, 'ws');
const [baseUrl, setBaseUrl] = useState(`${ws}${path}`);
const [token, setToken] = useState<string | null>(null);
const socketUrl = useMemo(
() => (token ? `${baseUrl}?token=${token}` : baseUrl),
[baseUrl, token]
);
const socketUrl = useMemo(() => {
const parseUrl = new URL(baseUrl);
if (token) {
parseUrl.searchParams.set('token', token);
}
return parseUrl.toString();
}, [baseUrl, token]);
const debouncedOnMessage = useMemo(() => {
if (options?.debounce) {