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>
);
}

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
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
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-storageFor 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 = trueOn Expo, install @talkjs/expo instead:
npx expo install @talkjs/expo @notifee/react-native react-native-webview @react-native-async-storage/async-storage expo-build-propertiesExpo 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.
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.
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
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.
