SendbirdProvider
SendbirdProvider is the most important component in UIKit for React because it's the context provider that passes the Chat SDK down to the child components. The custom hook is used to easily pass down data through components. By using the useSendbird() custom hook, you can implement Sendbird Chat SDK for React in any of the components under SendbirdProvider. The following table shows a list of properties of the SendbirdProvider component.
Note:
SendbirdProvidermust be placed at the top level of your app.
List of properties
Properties
| Required | Type | Description |
|---|---|---|
appId | string | Specifies the |
userId | string | Specifies the unique ID of the user. |
| Optional | Type | Description |
|---|---|---|
accessToken | string | Specifies an opaque string that identifies the user. It's recommended that every user has their own access token and provides it upon login for security. (Default: |
theme | string | Specifies a style that's applied to the entire client app. Available themes are |
nickname | string | Specifies the user's nickname. (Default: |
profileUrl | string | Specifies the URL of the user's profile image. (Default: |
userListQuery | interface | Specifies the query factory class to retrieve a list of filtered users and manually added users. (Default: Chat SDK's |
dateLocale | locale | Specifies the prop to localize the date and time of the current user's client app using Localization object from date-fns. (Default: |
stringSet | object | Specifies a set of strings used in UIKit components. You can override the default language using the stringSet. (Default: |
colorSet | object | Specifies a set of colors used in the UIKit themes. You can override the theme using the colorSet. (Default: |
ThreadReplySelectType | function | Specifies the prop to direct users to view either the parent message or the thread when they click on a reply button in the group channel module. Acceptable values are: |
onStartDirectMessage | function | Specifies the prop to handle the action when a user starts a 1-to-1 channel by clicking the message on a user profile icon. (Default: |
onBeforeStartDirectMessage | function | Specifies a callback to customize the creation parameters of the 1-to-1 channel created by the built-in profile popup's Message button. It receives |
sdkInitParams | object | Specifies the parameters passed to the Chat SDK's |
| function | (Deprecated) Specifies the prop to handle the action when a user starts a 1-to-1 channel by clicking the message on a user profile icon. (Default: |
Note : The
Appcomponent internally managesSendbirdProvideras well as other components and can be used to configure the above properties.
Customize the direct message channel
You can customize the 1-to-1 channel that the default user profile popup creates by using the onBeforeStartDirectMessage prop. This optional prop is available on SendbirdProvider and App. It runs right before the default profile popup creates the channel, which allows you to adjust the creation parameters. The callback also receives the target users.
The profile popup opened by clicking an @mention also uses the renderUserProfile prop. If you already provide a custom renderer, it applies to the mention popup as well as avatar profile popups.
Whether onBeforeStartDirectMessage runs together with renderUserProfile depends on whether your custom popup keeps the built-in UserProfile component.
Wrap the built-in popup
If your custom popup renders the built-in UserProfile component, onBeforeStartDirectMessage still runs because the Message button is still rendered.
In the following example, MyCard and MyHeader represent your own components. Replace them with your application's components.
Replace the built-in popup
If your custom popup doesn't render UserProfile, onBeforeStartDirectMessage doesn't run. In this case, create the channel yourself with the getCreateGroupChannel selector.
useSendbird
The useSendbird is a useState hook pattern that lets you access the internal state and actions available in sendbirdProvider. You can use the useSendbird custom hook to implement various functionalities such as displaying a user's profile or sending a user message. Refer to the example codes below.
List of state properties
The following table lists the state properties of useSendbird.
| Property name | Type | Description |
|---|---|---|
config | SendbirdStateConfig | Specifies the global configurations. |
stores | SendbirdStateStore | Specifies a set of the user or SDK states. |
eventHandlers | SBUEventHandlers | Specifies a set of the global event handlers. |
emojiManager | EmojiManager | Specifies the global |
List of actions properties
The following table lists the actions properties of useSendbird.
| Property name | Type | Description |
|---|---|---|
connect | function | Create the connection to the server. |
disconnect | function | Disconnect the current connection. |
updateUserInfo | function | Update the current user instance. |
Handle delayed connections
When the server is busy, it can delay a connection and tell the SDK how long to wait. The SDK then reconnects on its own. During that wait, SendbirdProvider and App show a modal with the estimated waiting time in MM:SS format.
The modal counts down every second and can't be dismissed. It closes once the SDK reconnects. When the countdown reaches zero, the estimated waiting time label and its value are hidden until the SDK reconnects, and only the title stays visible. The modal is shown by default and covers the screen above the other UIKit overlays.
Replace the delayed connection modal
You can replace the default modal with the renderConnectionDelayedModal prop of SendbirdProvider and App. If your layout doesn't fit the default modal, use this prop to render your own UI.
The function receives retryAfter, which is the number of seconds until the SDK retries. It is called again with the new value whenever the SDK reports a new delay. The retryAfter value doesn't tick by itself, so count it down in your component if you want a live timer. Return null to show nothing.
The returned element is rendered inside the provider, before its children, so you must position it yourself. The following example renders a banner.
To keep the modal look, use Modal from @sendbird/uikit-react/ui/Modal. It stacks like any other UIKit modal, so an open image viewer or menu can cover it. To keep it on top, give it a className with a higher z-index. The default modal uses 100100. The Modal component shows a close button unless you pass renderHeader. Handle the close button with onClose if users may dismiss it.
Initialization after a delayed connection
When the first connection is delayed, eventHandlers.connection.onFailed is still called with SendbirdErrorCode.DELAYED_CONNECTING, whose error code is 800221. The provider then waits. Once the SDK reconnects as the same user, the provider finishes initializing and calls onConnected.
You don't need to retry from onFailed for this error. Retrying, such as by remounting the provider, doesn't connect any sooner than waiting for the server delay to end. It only restarts the provider while the SDK is still waiting out the delay. If your app retries from onFailed, return early without retrying when you receive this error.