From c7599c74722864d54c96a3f3d52e28290abb9eac Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 11 Aug 2024 22:51:03 +0900 Subject: refactor(frontend): add stronger typing to useWebSocket() --- frontend/app/hooks/useWebSocket.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 frontend/app/hooks/useWebSocket.ts (limited to 'frontend/app/hooks/useWebSocket.ts') diff --git a/frontend/app/hooks/useWebSocket.ts b/frontend/app/hooks/useWebSocket.ts new file mode 100644 index 0000000..8fe688f --- /dev/null +++ b/frontend/app/hooks/useWebSocket.ts @@ -0,0 +1,14 @@ +import useWebSocketOriginal, { ReadyState } from "react-use-websocket"; + +export { ReadyState }; + +// Typed version of useWebSocket() hook. +export default function useWebSocket( + url: string, +): { + sendJsonMessage: (message: SendMessage) => void; + lastJsonMessage: ReceiveMessage; + readyState: ReadyState; +} { + return useWebSocketOriginal(url); +} -- cgit v1.2.3-70-g09d2