Skip to content
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

Channel provider - support multiple channels #1748

Open
mizrachiran opened this issue Apr 18, 2024 · 1 comment
Open

Channel provider - support multiple channels #1748

mizrachiran opened this issue Apr 18, 2024 · 1 comment
Labels
documentation Improvements or additions to public interface documentation (API reference or readme).

Comments

@mizrachiran
Copy link

mizrachiran commented Apr 18, 2024

Hi there,

I'm looking into updating my client lib to the new version, where the ChannelProvider context was introduced.
I used to use multiple channels in my components and I wonder if I should wrap my component with multiple ChannelProviders, one for each channel, or if there is a way to have 1 channel provider with multiple channel names.

Would appreciate your support.

Thanks!

┆Issue is synchronized with this Jira Task by Unito

@VeskeR
Copy link
Contributor

VeskeR commented Apr 18, 2024

Hi @mizrachiran !

There is no way to provide a list of channel names for a ChannelProvider. Each ChannelProvider corresponds to a single channel name with its options.

If in your use case you intend to use different channel names inside one component, then you would need to wrap that component in multiple ChannelProvider like this:

<ChannelProvider channelName="your-channel-name">
  <ChannelProvider channelName="your-other-channel-name">
    <YourComponentWithMultipleChannels></YourComponentWithMultipleChannels>
  </ChannelProvider>
</ChannelProvider>

However, there is no strict restriction on where exactly you declare a ChannelProvider, as long as it wraps your component which uses the corresponding channel name. This means that if you use different channel names in different components, you can wrap them individually in a more structured way that would suit your app structure.
So you could have something like this:

// somewhere high in your component hierarchy you declare AblyProvider, usually in your App component
<AblyProvider client={client}>
  <ComponentAWrapper></ComponentAWrapper>
  <ComponentBWrapper></ComponentBWrapper>
</AblyProvider>

function ComponentAWrapper() {
  return (
    <ChannelProvider channelName="your-channel-name">
      <ComponentA></ComponentA>
    </ChannelProvider>
  );
}

function ComponentBWrapper() {
  return (
    <ChannelProvider channelName="your-other-channel-name">
      <ComponentB></ComponentB>
    </ChannelProvider>
  );
}

function ComponentA() {
  // uses 'your-channel-name' channel
  // ...
}

function ComponentB() {
  // uses 'your-other-channel-name' channel
  // ...
}

@VeskeR VeskeR added the documentation Improvements or additions to public interface documentation (API reference or readme). label Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to public interface documentation (API reference or readme).
Development

No branches or pull requests

2 participants