diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-11 22:51:03 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-11 22:51:12 +0900 |
| commit | c7599c74722864d54c96a3f3d52e28290abb9eac (patch) | |
| tree | 18ace008aa147f0ea17d4a3ecdba4b9794afd15d /frontend/app/hooks/useWebSocket.ts | |
| parent | fe8b14ccc77c829a2baa4034edb22daff9d5d8f8 (diff) | |
| download | iosdc-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.ts | 14 |
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); +} |
