MCPcopy Create free account
hub / github.com/code100x/chess / useSocket

Function useSocket

apps/native/hooks/useSocket.ts:10–31  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8};
9
10export const useSocket = () => {
11 const [socket, setSocket] = useState<WebSocket | null>(null);
12 // const user = useUser();
13
14 useEffect(() => {
15 const ws = new WebSocket(`${WS_URL}?token=${user.token}`);
16
17 ws.onopen = () => {
18 setSocket(ws);
19 };
20
21 ws.onclose = () => {
22 setSocket(null);
23 };
24
25 return () => {
26 ws.close();
27 };
28 }, [user]);
29
30 return socket;
31};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected