stream-chat-react icon indicating copy to clipboard operation
stream-chat-react copied to clipboard

bug: all the app examples are using StreamChat.getInstance() to initiate the client

Open MartinCupela opened this issue 2 years ago • 1 comments

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

MartinCupela avatar Jun 08 '22 12:06 MartinCupela

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 unique StreamChat client, i.e create a StreamChat instance and retrieve it wherever you need it on your app to perform API calls. After calling it once, any following getInstance() call will return the initial StreamChat instance. This should prevent from accidentally creating multiple StreamChat 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.

tplk avatar Jun 15 '22 15:06 tplk