stream-chat-react
stream-chat-react copied to clipboard
bug: all the app examples are using StreamChat.getInstance() to initiate the client
Describe the bug
Client initiation with StreamChat.getInstance
method is not reliable and leads to multiple / no client instances in the application state. We have already updated the documentation demonstrating alternative approach, but everywhere else the old instantiation approach is used.
Acceptance criteria All code snippets converted:
[ ] API Tour [ ] stream-chat-react/examples [ ] Watercooler [ ] website-react-examples
Hi! Can you clarify why is it advised the other way around in the docs right now?
https://getstream.io/chat/docs/javascript/?language=javascript#chat-client
Please also note here the usage of
StreamChat.getInstance()
available since[email protected]
. This new Singleton pattern allows you to instantiate a uniqueStreamChat
client, i.e create aStreamChat
instance and retrieve it wherever you need it on your app to perform API calls. After calling it once, any followinggetInstance()
call will return the initialStreamChat
instance. This should prevent from accidentally creating multipleStreamChat
instances.This new Chat client version is backward compatible. That means users can continue using
new StreamChat()
if they use an older version of the library or for any other reason.