-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[🐛] Best Practices for handling multiple channels on the same screen #2824
Comments
Hey @arekkubaczkowski, I hope I can answer your questions with the best that I know.
About this one, I don't think you really need multiple chat instances to simulate multiple-channel environments in your application. This doesn't seem to be a good practice and can be a source of undetected bugs in the future. It is strange that if a channel has a different channel ID, how would the message from one channel come to the other channel? Do you have snippets to explain it to us? In the ChannelList, we have seen this issue since our Channel events don't respect user custom filters. This is something that the end user should handle, and this is something you can handle using our event overrides props for ChannelList, but for Channel, I am assuming it to work automatically if it's watched appropriately. For channels, the messages of one channel should technically not pop onto other channels.
This is something you would have to necessarily do for channels if you don't have a channel list with
Unless and until your component is wrapped with the |
@khushal87 thank you for your input, I am afraid that we misunderstood each other. Let me clarify my concerns: We need to handle multiple channels within the same screen, as well as display its content in multiple places across the same screen each of those places needs to be rendered independently but across the same screen. Which means that I need to have an access to the channel instances from any part of that screen (in fact we have more widgets that display some content based on the channel data that come from getstream events). That approach makes it difficult to handle it based on the rules that you've mentioned above, I am not able to wrap the entire screen with the |
Hey @arekkubaczkowski, you can have multiple channel context/channel wrappers in your application, but having multiple Chat instances for each Channel is not a thing that we recommend doing. Technically, that could lead you to problems. |
@khushal87 I tried using a single Chat instance to render multiple Channel components, but this caused issues with conflicting messages between the two channels. Specifically, both MessageList components displayed messages based on the latest channel update. For example, when a new message arrived in Channel A, both message lists showed messages from Channel A. Similarly, when a new message arrived in Channel B, both lists switched to displaying messages from Channel B. Simulator.Screen.Recording.-.iPhone.15.Pro.-.2025-01-07.at.14.40.51.mp4 |
Issue
In our application, we currently display multiple channels on the same screen. To achieve this, we are:
• Is there a recommended way to keep channel instances globally accessible while ensuring they remain properly synchronized?
• How can we avoid conflicts or issues when the same channel is accessed and managed from different parts of the app?
Could you clarify if this is the correct approach for managing multiple channels on the same screen? Are there any best practices or alternative solutions we should consider to ensure proper functionality and performance?
We would greatly appreciate your guidance on this matter!
Steps to reproduce
Steps to reproduce the behavior:
etc...
Expected behavior
Project Related Information
Customization
Click To Expand
Offline support
Environment
Click To Expand
package.json
:# N/A
react-native info
output:stream-chat-react-native
version you're using that has this issue:e.g. 5.4.3
e.g. Android 10
e.g. iPhone 11
Additional context
Screenshots
Click To Expand
The text was updated successfully, but these errors were encountered: