mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-11 21:29:09 -05:00
17 lines
424 B
TypeScript
17 lines
424 B
TypeScript
import * as React from "react";
|
|
import { useSocket } from "~/utils/socketContext";
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
export function useSocketEvent(event: string, handler: (data: any) => void) {
|
|
const socket = useSocket();
|
|
|
|
React.useEffect(() => {
|
|
if (!socket) return;
|
|
socket.on(event, handler);
|
|
|
|
return () => {
|
|
socket.off(event);
|
|
};
|
|
}, [socket, handler, event]);
|
|
}
|