From 98612e74e04c5482dad94c2cf48b2a3d1b05bba7 Mon Sep 17 00:00:00 2001 From: Gourav Bhardwaj Date: Wed, 7 May 2025 23:26:23 -0700 Subject: [PATCH] Fix order of .on() and .connect() in chat example --- src/content/learn/reusing-logic-with-custom-hooks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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]); }