In-App UI
Expo
SDK
Reference

Expo SDK API reference

Complete API reference for the Knock Expo SDK.

In this section, you'll find the complete documentation for the components exposed in @knocklabs/expo, including the props available.

Note: You can see a reference for the methods available for the Knock class, as well as a Feed instance under the client JS docs.

Components

#

KnockProvider

#

The top-level provider that connects to Knock with the given API key and authenticates a user.

Props

#

Accepts KnockProviderProps

apiKey*string

The public API key for the environment.

userUserIdentificationOptions

User identification data.

userTokenstring

A JWT that identifies the authenticated user, signed with the private key provided in the Knock dashboard. Required to secure your production environment. Learn more.

enabledboolean

Defaults to true. When false, children still render but the Knock client stays idle: no identify call, no API requests, and no websocket. Flipping it to true authenticates and connects the client; flipping it back to false disconnects it and clears its data. Use it to defer activity until you have a complete identity (see below).

hoststring

A custom API host for Knock.

i18nI18nContent

An optional set of translations to override the default en translations used in the feed components.

Deferring activity with enabled

#

KnockProvider takes an enabled prop that defaults to true. When it's false, the provider still renders its children, but the Knock client sits idle: it doesn't identify the user, make any API requests, or open a websocket. Set it back to true and the client authenticates and connects; set it to false again and it disconnects and clears its data.

This is the recommended way to gate the provider on a complete identity — for example, an enhanced-security user token that isn't ready on the first render — rather than mounting and unmounting KnockProvider as that identity changes:

Auto push-notification registration also waits for enabled to become true, so a user isn't shown the OS permission prompt until client authentication completes. When enabled becomes true, feed components remount and reload their data. To react to these transitions in your own components, use the useKnockAuthState hook.

KnockFeedProvider

#

The feed-specific provider that connects to a feed for that user. Must be a child of the KnockProvider.

Props

#

Accepts KnockFeedProviderProps:

feedId*string

The channel ID of the in-app feed to be displayed.

defaultFeedOptionsFeedClientOptions

Set defaults for tenant, has_tenant, source, archived to scope all subsequent feed queries.

colorModeColorMode

Sets the theme as either light or dark mode (defaults to light).

KnockExpoPushNotificationProvider

#

A context provider designed to streamline the integration of Expo push notifications within your React Native application. It facilitates the registration of device push tokens with the Knock backend, enabling the delivery of notifications. Moreover, this provider empowers developers to define custom behavior for handling notifications when they are received or interacted with, either by tapping or performing another action. By default, it provides a basic notification handling strategy, but it also allows for custom logic to be easily implemented according to specific application needs.

Note: Must be a child of the KnockProvider.

Props

#

Accepts KnockExpoPushNotificationProviderProps:

knockExpoChannelId*string

The channel ID of your Expo channel from Knock.

customNotificationHandlerPromise<Notifications.NotificationBehavior>

Allows developers to define custom behavior for handling notifications, including whether to show alerts, play sounds, or set badge counts.

autoRegisterboolean

When true, the Expo provider retrieves a push token from Expo and stores it as channel data on the user. Registration waits until the client is authenticated, so a user isn't shown the OS permission prompt until client authentication completes.

Hooks

#

useKnock

#

The KnockProvider exposes a useKnock hook for all child components.

Returns: Knock, an instance of the Knock JS client.

Example:

useKnockFeed

#

The KnockFeedProvider exposes a useKnockFeed hook for all child components.

Returns: KnockFeedProviderState

knockKnock

The instance of the Knock client.

feedClientFeed

The instance of the authenticated Feed.

useFeedStoreUseStore<FeedStoreState>

A zustand store containing the FeedStoreState.

statusFilterStatus

Current value of the filter status for the Feed.

setStatusfunction

A function to set the current FilterStatus.

colorModeColorMode

The current theme color.

Example:

useAuthenticatedKnockClient

#

Creates an authenticated Knock client.

Returns: Knock instance, authenticated against the user

Example:

useKnockAuthState

#

Subscribes to a Knock client's authentication state, re-rendering when the authenticated user changes. Use it to react to the enabled prop on KnockProvider flipping between states.

Returns: KnockAuthState

status'authenticated' | 'unauthenticated'

Whether a user is authenticated to the client.

userIdstring | undefined | null

The ID of the authenticated user, or undefined when no user is authenticated.

userTokenstring | undefined

The user token in use for the authenticated user, when one was provided.

Example:

useNotifications

#

Creates a Feed instance for the provided Knock client which creates a stateful, real-time connection to Knock to build in-app experiences.

Returns: Feed instance

Example:

useTranslations

#

Exposed under KnockI18nProvider child components.

Returns:

localestring

The current locale code (defaults to en).

t(key: string) => string

A helper function to get the value of a translation from the current Translations.

useExpoPushNotifications

#

The KnockExpoPushNotificationProvider exposes a useExpoPushNotifications hook for all child components, enabling them to interact with push notification functionalities and state.

Returns: KnockExpoPushNotificationContextType

expoPushTokenstring | null

The Expo push token for the current device.

registerForPushNotifications() => Promise<void>

A function to initiate the push notification registration process.

registerPushTokenToChannel(token: string, channelId: string) => Promise<ChannelData | void>

Registers the device's push token with a specific channel in the Knock backend.

unregisterPushTokenFromChannel(token: string, channelId: string) => Promise<ChannelData | void>

Removes the device's push token from a specific channel in the Knock backend.

onNotificationReceived(handler: (notification: Notifications.Notification) => void) => void

Sets a custom handler for notifications received while the app is in the foreground.

onNotificationTapped(handler: (response: Notifications.NotificationResponse) => void) => void

Sets a custom handler for user interactions with notifications.

Example:

Types

#

UserIdentificationOptions

#

User identification data to pass through to the authenticate method.

idstring*

The id for the user.

[attribute_name]any

Attribute to attach to the user on identification.

ChannelData

#
channel_idstring*

The unique identifier for the channel.

dataany

Channel data for a given channel type.

I18nContent

#

Used to set translations available in the child components exposed under KnockFeedProvider and KnockSlackProvider. Used in the useTranslations hook.

Note: locale must be a valid locale code.

New chat