hardExtra#97

WebSocket connection hook

Prompt

Create a custom useWebSocket hook that:

  1. Connects to a WebSocket URL
  2. Returns the latest message
  3. Reconnects on disconnect — but never after unmount
  4. Cleans up the socket AND any pending reconnect timer on unmount

Hints

Solution

Your Code

15 min

Tests

Click Run to test your code