Docs menu

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

typePayload and meaning
readyThe chat has rendered.
closeThe user closed the chat.
openUrlurl: a link the chat opened.
errorcode: load_failed, handshake_timeout or renderer_crashed.
identityErrorreason: why the identity token failed.
storageUnavailablereason: peer-absent (AsyncStorage is not installed) or load-threw. Every launch is then a new anonymous user.
unreadCountChangedcount: unread replies, 0 to 100. Only sent while the chat page is loaded.
installRefChangedinstallRef: the anonymous user's new key, or null after logout().

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.