aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/hooks/useWebSocket.ts
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-11 22:51:03 +0900
committernsfisis <nsfisis@gmail.com>2024-08-11 22:51:12 +0900
commitc7599c74722864d54c96a3f3d52e28290abb9eac (patch)
tree18ace008aa147f0ea17d4a3ecdba4b9794afd15d /frontend/app/hooks/useWebSocket.ts
parentfe8b14ccc77c829a2baa4034edb22daff9d5d8f8 (diff)
downloadiosdc-japan-2024-albatross-c7599c74722864d54c96a3f3d52e28290abb9eac.tar.gz
iosdc-japan-2024-albatross-c7599c74722864d54c96a3f3d52e28290abb9eac.tar.zst
iosdc-japan-2024-albatross-c7599c74722864d54c96a3f3d52e28290abb9eac.zip
refactor(frontend): add stronger typing to useWebSocket()
Diffstat (limited to 'frontend/app/hooks/useWebSocket.ts')
-rw-r--r--frontend/app/hooks/useWebSocket.ts14
1 files changed, 14 insertions, 0 deletions
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<ReceiveMessage, SendMessage>(
+ url: string,
+): {
+ sendJsonMessage: (message: SendMessage) => void;
+ lastJsonMessage: ReceiveMessage;
+ readyState: ReadyState;
+} {
+ return useWebSocketOriginal(url);
+}