diff --git a/src/content/learn/reusing-logic-with-custom-hooks.md b/src/content/learn/reusing-logic-with-custom-hooks.md index ea8d0a31322..d6cdab9590e 100644 --- a/src/content/learn/reusing-logic-with-custom-hooks.md +++ b/src/content/learn/reusing-logic-with-custom-hooks.md @@ -997,10 +997,10 @@ export function useChatRoom({ serverUrl, roomId, onReceiveMessage }) { roomId: roomId }; const connection = createConnection(options); - connection.connect(); connection.on('message', (msg) => { onMessage(msg); }); + connection.connect(); return () => connection.disconnect(); }, [roomId, serverUrl]); }