Sendbird UIKit: subscribe for new messages for user?

Hi @Dmytro

Apologies about the docs - we understand that docs are the most important part of any library - we are working on improving them. As a first step, we have made a bunch of examples on various use cases for UIKit. You can find them here

I recommend you to follow the pattern from https://github.com/sendbird/SendBird-JavaScript/tree/master/uikit-samples#2-5-customizing-messageinput

Using withSendBird HOC to access SDK to your custom component
And from there, use the SDK instance and use event handlers to listen to events


import React, { useEffect } from "react";
import { sendBirdSelectors, withSendBird } from "sendbird-uikit";

const CustomComponent = (props) => {
  const {sdk} = props;
  useEffect(() => {
    var ChannelHandler = new sb.ChannelHandler();
    ChannelHandler.onMessageReceived = function(channel, message) {
      // your custom logic
    };
    sb.addChannelHandler(UNIQUE_HANDLER_ID, ChannelHandler);
    return () => {
      // cleanup
      sb.removeChannelHandler(UNIQUE_HANDLER_ID);
    }
  }, [sdk])
  return (
    <div />
  )
}

const mapStoreToProps = store => {
  const sdk = sendBirdSelectors.getSdk(store);
  return {
    sdk,
  };
};

export default withSendBird(CustomComponent, mapStoreToProps);

^^ If this didnt help, please let me know

1 Like