Skip to content

Commit caf13c5

Browse files
committed
fix: use latest options value on new client creation
1 parent 743b587 commit caf13c5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from 'react';
1+
import { useEffect, useRef, useState } from 'react';
22

33
import { StreamChat } from 'stream-chat';
44

@@ -30,10 +30,11 @@ export const useCreateChatClient = ({
3030
setCachedUserData(userData);
3131
}
3232

33-
const [cachedOptions] = useState(options);
33+
const optionsRef = useRef(options);
34+
optionsRef.current = options;
3435

3536
useEffect(() => {
36-
const client = new StreamChat(apiKey, undefined, cachedOptions);
37+
const client = new StreamChat(apiKey, undefined, optionsRef.current);
3738
let didUserConnectInterrupt = false;
3839

3940
const connectionPromise = client.connectUser(cachedUserData, tokenOrProvider).then(() => {
@@ -51,7 +52,7 @@ export const useCreateChatClient = ({
5152
console.log(`Connection for user "${cachedUserData.id}" has been closed`);
5253
});
5354
};
54-
}, [apiKey, cachedUserData, cachedOptions, tokenOrProvider]);
55+
}, [apiKey, cachedUserData, tokenOrProvider]);
5556

5657
return chatClient;
5758
};

0 commit comments

Comments
 (0)