For AI agents: Find a documentation index at https://talkjs.com/llms.txt (full content at https://talkjs.com/llms-full.txt). Get a markdown version of any page by appending .md to its URL path.
Skip to content

React Native

React Native chat SDK with pre-built UI

Add a ready-made chat screen to your iOS and Android app with a TalkJS package for React Native CLI or Expo. We store and deliver every message and send the push notifications. And if you also have a web app, your users get one chat across both.

import React from 'react';
import * as TalkRn from '@talkjs/react-native';

function ChatComponent() {
  const me = {
    id: '123456789',
    name: 'Alice',
    email: 'alice@example.com',
    photoUrl: 'https://talkjs.com/images/avatar-1.jpg',
    welcomeMessage: 'Hey there! How are you? :-)',
  };

  const other = {
    id: '987654321',
    name: 'Sebastian',
    email: 'Sebastian@example.com',
    photoUrl: 'https://talkjs.com/images/avatar-5.jpg',
    welcomeMessage: 'Hey, how can I help? https://google.com',
  };

  const conversationBuilder = TalkRn.getConversationBuilder(
    TalkRn.oneOnOneId(me, other)
  );

  conversationBuilder.setParticipant(me);
  conversationBuilder.setParticipant(other);

  return (
    <TalkRn.Session appId="<MAGIC_APP_ID>" me={me}>
      <TalkRn.Chatbox conversationBuilder={conversationBuilder} />
    </TalkRn.Session>
  );
}
Avatar
Hey, I’m trying to lift state up from a child component, but I’m getting undefined errors. Any ideas?
8m ago
Avatar
Are you passing the state and the setState function correctly as props?
10m ago
Avatar
I think so, yes.
7m ago
OK hand emoji
Thinking emoji
Avatar
Maybe you’re not binding the handler in the constructor. That might be the issue.
2m ago
Avatar
Say something…
Avatar
Avatar
4
AI integration strategy
Andrea, Robert, Nikki, Filip
Avatar
Andrea
10m ago
Hey team, how do you think we can integrate AI into our project?
Avatar
Robert
8m ago
Maybe we can use AI for data analysis. It can help us find trends faster.
Avatar
Nikki
7m ago
Good idea @Robert. What about automating customer support? AI agents could handle common queries.
Avatar
Filip
2m ago
00:15
1x
Say something…
Classtime
Decathlon
Riot Games
Hyundai

One chat across your web app and your React Native app

Your web app and your React Native app share one app ID, so they share users and conversations: a buyer messages a seller from your website, and the seller replies from the app. One subscription covers both, plus any other websites and apps of the same product.

The screens match too if your web app runs the Classic JavaScript SDK. The React Native SDK runs that same chat UI, and one Theme Editor theme styles both. New web projects start on the Components SDK, which you theme in code (see React chat), and a Components SDK for React Native is coming.

Alice’s conversation with Sebastian, on your website and in your app

Sebastian
Is the bike still for sale?
Yes. Come by on Saturday?
Saturday works for me.
Your web appClassic JavaScript SDKApp ID: tA7Lq2Xe
Sebastian
Is the bike still for sale?
Yes. Come by on Saturday?
Saturday works for me.
Your React Native app@talkjs/react-nativeApp ID: tA7Lq2Xe
One app ID, one conversation: Alice sees the same messages on your website and in your app.

What runs inside the React Native chat screen

Your Chatbox is TalkJS’s JavaScript chat in a WebView. @talkjs/react-native and @talkjs/expo load talk.js from cdn.talkjs.com in react-native-webview and make the same calls a website makes: createChatbox() for a Chatbox and createInbox() for a ConversationList.

You get the web chat’s extras too, like an HtmlPanel that puts your own HTML above the message field.

Both packages are stable for production. We keep them backward compatible, and they run on the same TalkJS backend that carries 130M+ messages a month.

Choose the TalkJS React Native SDK if you want to add messaging to an existing iOS or Android app and keep your own navigation. Embed a Chatbox on a screen where two users need to talk, or add a ConversationList so they can return to earlier conversations.

Inside a TalkJS chat screen, top to bottom

The layers of a TalkJS chat screen in React NativeFive stacked layers: your screen and navigation, Chatbox or ConversationList, react-native-webview, talk.js from cdn.talkjs.com, and your TalkJS app.Your screen and navigationReact Native, your codeChatbox or ConversationList@talkjs/react-native or @talkjs/exporeact-native-webviewA WebView inside your screentalk.js from cdn.talkjs.comCalls createChatbox() or createInbox()Your TalkJS appYour app ID, users, and conversations
The blue box is the same talk.js a website loads with the Classic JavaScript SDK.

Install the React Native chat SDK: CLI or Expo

There are two packages with the same features: @talkjs/react-native for React Native CLI apps and @talkjs/expo for Expo. Both need React Native 0.70 or later. On React Native CLI, install the native peer dependencies with it:

npm install --save @talkjs/react-native @notifee/react-native @react-native-community/push-notification-ios @react-native-firebase/app @react-native-firebase/messaging react-native-webview @react-native-async-storage/async-storage

For iOS, add these lines to your Podfile’s target section, then run npx pod-install:

pod 'Firebase', :modular_headers => true
pod 'FirebaseCore', :modular_headers => true
pod 'GoogleUtilities', :modular_headers => true
$RNFirebaseAsStaticFramework = true

On Expo, install @talkjs/expo instead:

npx expo install @talkjs/expo @notifee/react-native react-native-webview @react-native-async-storage/async-storage expo-build-properties

Expo apps also need Notifee’s Maven repository in app.json, even without push notifications, or the Android build fails:

{
  "expo": {
    "plugins": [
      // Other plugins
      [
        "expo-build-properties",
        {
          "android": {
            "extraMavenRepos": [
              "../../node_modules/@notifee/react-native/android/libs"
            ]
          }
        }
      ]
    ]
  }
}

@talkjs/expo doesn’t run in Expo Go, so test your app in a development build.

For a first chat, a Session connects one user and a Chatbox inside it shows one conversation. Replace <MAGIC_APP_ID> with your app ID, and on Expo, import from '@talkjs/expo':

import React from 'react';
import * as TalkRn from '@talkjs/react-native';

function ChatComponent() {
  const me = {
    id: '123456789',
    name: 'Alice',
    email: 'alice@example.com',
    photoUrl: 'https://talkjs.com/images/avatar-1.jpg',
    welcomeMessage: 'Hey there! How are you? :-)',
  };

  const other = {
    id: '987654321',
    name: 'Sebastian',
    email: 'Sebastian@example.com',
    photoUrl: 'https://talkjs.com/images/avatar-5.jpg',
    welcomeMessage: 'Hey, how can I help? https://google.com',
  };

  const conversationBuilder = TalkRn.getConversationBuilder(
    TalkRn.oneOnOneId(me, other)
  );

  conversationBuilder.setParticipant(me);
  conversationBuilder.setParticipant(other);

  return (
    <TalkRn.Session appId="<MAGIC_APP_ID>" me={me}>
      <TalkRn.Chatbox conversationBuilder={conversationBuilder} />
    </TalkRn.Session>
  );
}

For an inbox, put a ConversationList on its own screen and let onSelectConversation navigate to a screen with a Chatbox:

import * as TalkRn from '@talkjs/react-native';

const me: TalkRn.User = { id: '123456789', name: 'Alice' };

export function Inbox() {
  return (
    <TalkRn.Session appId="<APP_ID>" me={me} tokenFetcher={async () => 'TOKEN'} enablePushNotifications={true}>
      <TalkRn.ConversationList
        onSelectConversation={(event) => console.log(event.conversation.id)}
      />
    </TalkRn.Session>
  );
}

The ConversationList reference lists every prop, and the React Native SDK docs have the full guide. These steps use version 0.17.1 of @talkjs/react-native and @talkjs/expo.

Before you go live, turn on authentication. Your server signs a JWT for each user with your secret key, and the app passes it to Session as token, or through a tokenFetcher that gets a fresh one. Authentication stays off on a new account until you enable it in your dashboard.

Push notifications in a React Native app

Push goes out from our servers through Firebase Cloud Messaging on Android and APNs on iOS (Firebase works on iOS too), with the FCM and APNs keys you upload in your TalkJS dashboard. In your app, call registerPushNotificationHandlers in your entry file, outside any component. It also creates the Android notification channel. Apps that target Android 13 or later also request POST_NOTIFICATIONS:

import { AppRegistry, Platform, PermissionsAndroid } from 'react-native';
import { registerPushNotificationHandlers } from '@talkjs/react-native';

import App from './App';
import { name as appName } from './app.json';

if (Platform.OS === 'android') {
  PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS);
}

registerPushNotificationHandlers(
  {
    channelId: 'com.example.reactnativetalkjs.messages',
    channelName: 'My Messages',
  },
  { useFirebase: false }
);

AppRegistry.registerComponent(appName, () => App);

index.js in a React Native CLI app. The version in the React Native push notifications guide also asks for iOS permissions.

Then set enablePushNotifications={true} on Session, and users get notifications while the app is in the background. Expo apps can use expo-notifications instead of React Native Firebase (see the Expo push guide). Our mobile chat SDK page covers how push works on iOS and Android.

Styleseat logo
Because implementing TalkJS was as fast and easy as it was, we were able to greenlight and move this project along very quickly. Had we not chosen this path, the feature would have either been delayed, or shelved due to the resources needed to implement it.
Sean Elliot
Engineering Manager, Styleseat

Ready-made chat components you can customize

The Chatbox and ConversationList come with a pre-built chat UI. You restyle it in the Theme Editor in your dashboard, and the theme prop gives one screen a different theme.

If you’d rather draw the chat with native views

Your native chat UI
Could you send the pickup address?
Of course. I’ll send it now.
TalkJS Swift or Kotlin Data APIMessage storage and delivery

Then you’re looking at a chat UI library. Gifted Chat is a full chat UI for React Native under the MIT license. It’s in maintenance mode now. New work happens in the @kesha-antonov/react-native-chat fork.

The library draws the screens. Storing the messages, getting them to the other phone, and push are yours to build. With React Native Firebase, onMessage doesn’t fire while the app is in the background or quit, so you write a background handler. A force-quit app gets nothing until it’s opened again, and iOS simulators don’t receive FCM messages. Sending through FCM takes a server that stores credentials and device tokens and retries with back-off. If Socket.IO carries your live messages, it delivers at most once by default and doesn’t replay events a disconnected client missed.

If your app is native Kotlin or Swift, TalkJS handles the backend half: we store and deliver the messages. Writing a native Android app in Kotlin? The TalkJS Android chat SDK gives you ready-made chat screens for Jetpack Compose, or the data to draw your own. For Swift, see the iOS chat SDK. Comparing hosted chat kits for Expo? Our mobile chat SDK page counts the npm packages each one adds.

FAQs

No. Some of the dependencies of @talkjs/expo contain native code, which Expo Go can’t load, so you run your app in an Expo development build. Stream’s and CometChat’s Expo SDKs need a development build too.

React Native 0.70 or later. Version 0.17.1 of both @talkjs/react-native and @talkjs/expo lists react-native >=0.70 as a peer dependency.

Yes. On native Android, TalkJS Android Components gives you ready-made chat screens for Jetpack Compose, and the Kotlin Data API is there if you’d rather build your own. On native iOS, the Swift Data API is headless: TalkJS handles the messages, and you build the chat screens. For one pre-built chat UI on both iOS and Android, use the React Native SDK, which draws the chat in a WebView, or the Flutter SDK.

You pay per monthly active user, not per message, and only once you go live: every plan has a free development mode. Basic is $279 a month, or $239 a month billed annually, with 10,000 monthly active users. Your web app and your React Native app can share one subscription when they’re one product with the same users and conversations. Push, email, and SMS notifications are on every plan, and SMS is charged separately. See pricing for the other plans.