Skip to content

Commit 78b4a96

Browse files
committed
fix: ensure correct user id is used in useEffect cleanup
1 parent 7e7a1b3 commit 78b4a96

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

package/src/components/Chat/hooks/useCreateChatClient.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ export const useCreateChatClient = ({
3232
optionsRef.current = options;
3333

3434
useEffect(() => {
35+
const userData = userDataRef.current;
36+
3537
const client = new StreamChat(apiKey, undefined, optionsRef.current);
3638
let didUserConnectInterrupt = false;
3739

38-
const connectionPromise = client.connectUser(userDataRef.current, tokenOrProvider).then(() => {
40+
const connectionPromise = client.connectUser(userData, tokenOrProvider).then(() => {
3941
if (!didUserConnectInterrupt) {
4042
setChatClient(client);
4143
}
@@ -47,7 +49,7 @@ export const useCreateChatClient = ({
4749
connectionPromise
4850
.then(() => client.disconnectUser())
4951
.then(() => {
50-
console.log(`Connection for user "${userDataRef.current.id}" has been closed`);
52+
console.log(`Connection for user "${userData.id}" has been closed`);
5153
});
5254
};
5355
// we should recompute the client on user id change

0 commit comments

Comments
 (0)