mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-11 05:05:07 -05:00
19 lines
491 B
TypeScript
19 lines
491 B
TypeScript
import type { ReactNode } from "react";
|
|
import { createContext, useContext } from "react";
|
|
import type { Socket } from "socket.io-client";
|
|
|
|
type ProviderProps = {
|
|
socket: Socket | undefined;
|
|
children: ReactNode;
|
|
};
|
|
|
|
const context = createContext<Socket | undefined>(undefined);
|
|
|
|
export function useSocket() {
|
|
return useContext(context);
|
|
}
|
|
|
|
export function SocketProvider({ socket, children }: ProviderProps) {
|
|
return <context.Provider value={socket}>{children}</context.Provider>;
|
|
}
|