1

I want to implement a hook to update my view with unread messages count without constantly making a request to the server to get the total number of channels with unread messages with this request . I am using React + Next.js, I can't seem to find any documentation on how to get into the channels unread messages properties via sdk or <ChannelList /> ui component. Sendbird support is practically useless, if anyone knows please help

1 Answers1

1

Disclaimer, I work for Sendbird.

When utilizing the UIKit, you'll need to access the underlying SDK instance in order to utilize methods like getTotalUnreadMessageCount() or getTotalUnreadChannelCount(). First you'll need to get an instance of the current context which can be obtained by calling useSendbirdStateContext() which can be imported from sendbird-uikit. Note that this does need to be called within a component that is wrapped in the SendBirdProvider HOC.

const context = useSendbirdStateContext();
const sdkInstance = sendBirdSelectors.getSdk(context);

I created an example of this for you on codesandbox: https://codesandbox.io/s/usesendbirdstatecontext-example-s8eful

  • 1
    Wow, Thanks so much for the answer. But I'm now having ```SendBirdException: Command received no ack.``` Error, I am using Next.js and Sendbird UI Kit v2. And also ```SendBirdException: QueryInProgress ``` when scrolling through list of users, is there any way I can fix it, if not how can I at least handle the exceptions so it won't break my app on client side. I see people are also facing the same issue [in community](https://community.sendbird.com/t/sendbird-uikit-react-v2-with-nextjs-error-command-received-no-ack/5025) –  Jul 17 '22 at 10:57
  • You can even see the error in your [codesandbox](https://codesandbox.io/s/usesendbirdstatecontext-example-s8eful) example above –  Jul 17 '22 at 12:17
  • @AbdulrahimIliasu As you’ve seen on the community, the team is already investigating. I’d follow the community thread you commented on for further updates. – Tyler Hammer Jul 18 '22 at 23:52
  • This solution does not work anymore @TylerHammer – Luis Contreras Jan 13 '23 at 19:30
  • 1
    @LuisContreras Unfortunately, it'll be hard to troubleshoot in stack overflow comments with the amount of data/questions needing answering. I would suggest heading over to the Sendbird community to get more detailed help. – Tyler Hammer Jan 16 '23 at 07:41