mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-13 06:21:21 -05:00
16 lines
360 B
TypeScript
16 lines
360 B
TypeScript
import io from "socket.io-client";
|
|
import * as React from "react";
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
export function useSocketEvent(event: string, handler: (data: any) => void) {
|
|
React.useEffect(() => {
|
|
const socket = io();
|
|
|
|
socket.on(event, handler);
|
|
|
|
return () => {
|
|
socket.close();
|
|
};
|
|
}, [handler]);
|
|
}
|