React Native SDK
Events and errors
React to chat events, handle links and customise the error screen.
Pass onEvent to configure() (or to <MentioraWidget />) to follow what the chat does.
Listen for events
TS
Mentiora.configure({
widgetUrl,
onEvent: (event) => {
if (event.type === "unreadCountChanged") setBadge(event.count);
},
});A callback that throws does not break the chat.
Event types
type | Payload and meaning |
|---|---|
ready | The chat has rendered. |
close | The user closed the chat. |
openUrl | url: a link the chat opened. |
error | code: load_failed, handshake_timeout or renderer_crashed. |
identityError | reason: why the identity token failed. |
storageUnavailable | reason: peer-absent (AsyncStorage is not installed) or load-threw. Every launch is then a new anonymous user. |
unreadCountChanged | count: unread replies, 0 to 100. Only sent while the chat page is loaded. |
installRefChanged | installRef: the anonymous user's new key, or null after logout(). |
Links
By default the SDK opens https:, mailto: and tel: links with Linking. To handle a link yourself, return true from onOpenUrl:
TS
Mentiora.configure({
widgetUrl,
onOpenUrl: (url) => {
if (!url.startsWith("https://example.com/")) return false;
openInApp(url);
return true;
},
});Error screen
If the chat cannot load after retries, the SDK shows a screen with Retry and Dismiss. Change its text with strings, or replace it with renderError:
TSX
Mentiora.configure({
widgetUrl,
strings: { errorTitle: "Chat is offline" },
renderError: ({ code, retry, dismiss }) => (
<BrandedError code={code} onRetry={retry} onClose={dismiss} />
),
});strings keys are errorTitle, errorBody, retry and dismiss. A custom screen must offer dismiss, or the user cannot leave it.