Flashcards
Challenges
← PawWalk Academy
hard
Extra
#97
WebSocket connection hook
Prompt
Create a custom useWebSocket hook that:
Connects to a WebSocket URL
Returns the latest message
Reconnects on disconnect — but never after unmount
Cleans up the socket AND any pending reconnect timer on unmount
Hints
Show
Solution
Show
Your Code
15 min
Reset
Run
function useWebSocket(url) { // Your code here return { lastMessage, sendMessage } }
Tests
Click Run to test your code