A developer built a custom TypeScript class-based WebSocket library for React after finding existing solutions like react-use-websocket lacking key features. The library uses three core classes: WebsocketConnection (singleton per URL with heartbeat, reconnection, and exponential backoff), WebsocketSubscriptionApi (streaming
Table of contents
Why build it myself?Inspiration: TanStack Form's Class-Based APIsHow the Classes and Hooks Work TogetherPassing Class Instances in ReactTanStack Store in This SetupWhen to Use Which HookConnection Lifecycle: When It Stays Open and When It ClosesEdge Cases Worth KnowingFeature listDownload a copySummarySort: