Demonstrates @knocklabs/react-native in a bare React Native app. Mirrors the structure of the Android and iOS demos. For an Expo-managed example, see expo-example.
Six screens, each demonstrating one piece of the SDK:
- Startup — splash before sign-in
- Sign in — identifies the user with
KnockProvider - Main — the in-app feed via the prebuilt
<NotificationFeed />component - Compose message — the shape of a workflow trigger payload
- Preferences — read and write the user's channel-type preferences via
usePreferences - Switch tenant — scope the feed and preferences to a tenant
-
Install dependencies from the root of the monorepo.
yarn
-
Build the Knock packages.
yarn build:packages
-
Configure the app. Open
src/config.tsand replace theKNOCK_*placeholders with values from your Knock dashboard. -
Set up your React Native development environment. See the React Native environment setup guide.
-
For iOS, install the CocoaPods dependencies once.
cd ios && bundle install && bundle exec pod install && cd ..
-
Start Metro and launch on a simulator or device.
yarn start # In another terminal: yarn ios # or yarn android
All runtime configuration lives as flat constants in src/config.ts:
| Constant | What it is |
|---|---|
KNOCK_API_KEY |
Public API key. Dashboard → Developers → API keys. |
KNOCK_USER_ID |
A test user's ID. Comes from your auth system in production. |
KNOCK_IN_APP_CHANNEL_ID |
In-app feed channel ID. Integrations → In-app feed. |
KNOCK_PUSH_CHANNEL_ID |
APNs/FCM push channel ID. Integrations page. |
KNOCK_HOSTNAME |
Override for self-hosted or sandbox Knock. |
KNOCK_TENANT_A, KNOCK_TENANT_B |
Tenant IDs used by the tenant switcher. |
The Compose screen shows the shape of a workflow trigger payload but does not call Knock directly. Triggers require your secret API key, which must not live in a mobile app — POST the payload to a trusted backend that calls knock.workflows.trigger on your behalf.
The app wires KnockPushNotificationProvider so the SDK is ready to register device tokens, but the device-token registration code itself is not in this example. APNs and FCM setup require account-level configuration (certificates, Firebase project) that's out of scope here.