- added new websocket implementation
This commit is contained in:
23
src/app/context/WebSocketContext.ts
Normal file
23
src/app/context/WebSocketContext.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { createContext, useContext } from "react";
|
||||
import { ReadyState } from "react-use-websocket";
|
||||
import type { InfoBarData } from "../../types/types";
|
||||
|
||||
type InfoSocketState = {
|
||||
data: InfoBarData | null;
|
||||
readyState: ReadyState;
|
||||
sendJson: (msg: unknown) => void;
|
||||
};
|
||||
|
||||
export type WebSocketConextValue = {
|
||||
info: InfoSocketState;
|
||||
};
|
||||
|
||||
export const WebsocketContext = createContext<WebSocketConextValue | null>(null);
|
||||
|
||||
const useWebSocketContext = () => {
|
||||
const ctx = useContext(WebsocketContext);
|
||||
if (!ctx) throw new Error("useWebSocketContext must be used inside <WebSocketConext.Provider>");
|
||||
return ctx;
|
||||
};
|
||||
|
||||
export const useInfoSocket = () => useWebSocketContext().info;
|
||||
Reference in New Issue
Block a user