React SDK API reference

Complete API reference for the Knock React SDK.

In this section, you'll find the complete documentation for the components exposed in @knocklabs/react, 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.



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


Accepts KnockProviderProps

apiKey*stringThe public API key for the environment
userId*stringThe ID of the user for which to retrieve a feed
userTokenstringA JWT that identifies the authenticated user, signed with the private key provided in the Knock dashboard. Required to secure your production environment. Learn more.
onUserTokenExpiring(oldToken: string) => Promise<string | void>A callback to provide that will fire before a user Token expires. By default will fire 30s before the token is set to expire. If a string is returned from the resolved promise, that will be used as the new user token.
timeBeforeExpirationInMsnumberDetermines the amount of time in milliseconds before the token expires that the callback should be fired.
hoststringA custom API host for Knock
i18nI18nContentAn optional set of translations to override the default `en` translations used in the feed components


The KnockProvider exposes a useKnockClient hook for all child components.

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



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


Accepts KnockFeedProviderProps:

feedId*stringThe channel ID of the in-app feed to be displayed
defaultFeedOptionsFeedClientOptionsSet defaults for `tenant`, `has_tenant`, `source`, `archived` to scope all subsequent feed queries
colorModeColorModeSets the theme as either light or dark mode (defaults to light)


The KnockFeedProvider exposes a useKnockFeed hook for all child components.

Returns: KnockFeedProviderState

knockKnockThe instance of the Knock client
feedClientFeedThe instance of the authenticated Feed
useFeedStoreUseStore<FeedStoreState>A zustand store containing the FeedStoreState
statusFilterStatusCurrent value of the filter status for the Feed
setStatusfunctionA function to set the current FilterStatus
colorModeColorModeThe current theme color



The Slack-specific provider that connects to a Slack workspace for the given tenant. Must be a child of the KnockProvider.


Accepts KnockSlackProviderProps

knockSlackChannelId*stringThe ID of the Slack channel in the Knock dashboard that the Slack application is linked to.
tenant*stringThe ID of the tenant that will be storing the Slack access token


The KnockSlackProvider exposes a useKnockSlackClient hook for all child components.


connectionStatusConnectionStatusThe status of the auth connection to the given Slack client
setConnectionStatusfunctionA function to set the connection status
errorLabelstringAn error message about the connection status
setErrorLabelfunctionA function to set an error label
actionLabelstringA label that gives an action for the user to take, like 'Retry' or 'Disconnect'
setActionLabelfunctionA function to set the action label


General components


A generic Button component that can be used to add action buttons to items in a notifcation feed.


variantstringThe variant of the button; either `primary` or `secondary`. Defaults to `primary`.
loadingTextstringText to display while the button is loading.
isLoadingbooleanWhen true, will display a spinner next to the `loadingText` (if present).
isDisabledbooleanWhen true, will mark the button as disabled.
isFullWidthbooleanWhen true, will make the button occupy 100% of the parent container.
onClick*functionThe click handler to be invoked when the button is clicked.
childrenReactNodeThe text to display inside of the button.


Used to group and space multiple Button components into a single line.


children*ReactNodeOne or more `Button` components


A provider to inject translations into components.


i18nI18nContentA set of translations and a locale to use in child components via the `useTranslations` hook
children*ReactNodeOne or more `Button` components

Feed components



EmptyComponent*ReactNodeThe empty component to render, when not set defaults to <EmptyFeed />.
renderItemfunctionA function invoked per `FeedItem` to be rendered that should return a cell to be rendered in the feed. Useful when you want to render a custom feed cell. Defaults to rendering a `NotificationCell`.
renderHeaderfunctionA function invoked that returns a header to be rendered in the feed. Useful when you want to render a custom header. Defaults to rendering a `NotificationFeedHeader`.
onNotificationClickfunctionA custom function to be invoked when a notification cell is clicked.
onMarkAllAsReadClickfunctionA custom function to be invoked when the `Mark all as read` button is clicked.


Renders a NotificationFeed in a floating popover, rendered by popper-js.


Accepts the same base props as NotificationFeed, and overrides with the following:

isVisible*booleanWhether or not to show the popover.
onClose*functionThe function to be invoked when the popover is closed.
onOpenfunctionA function that's invoked whenever the feed popover is opened, useful for updating any items in view and marking them as read, seen, or archived.
buttonRef*RefObject<HTMLElement>A ref of the button to position the popover adjacent to.
closeOnClickOutsidebooleanWhen true, will close the popover whenever any area outside of the popover is clicked.
placementPlacementDetermines the popper-js position of the popover (defaults to `bottom-end`).



item*FeedItemThe feed item (notification) to render
onItemClickfunctionThe function to be invoked when the row is clicked
avatarReactNodeRender a custom avatar for the feed item
archiveButtonReactNodeRender a custom archive button for the feed item
childrenReactNodeA set of children to render inside of the cell, will be rendered under the main content in a `rnf-notification-cell__child-content` div. Useful for rendering action buttons.


Renders a notification bell icon, with a badge showing the number of unseen items present in the notification feed.


onClick*functionThe function to be invoked when the IconButton is clicked
badgeCountTypeenumOne of `unseen` | `unread` | `all` to determine which count to display

Slack components



slackClientId*stringThe client ID of your Slack application.
redirectUrlstringThe URL of your application to return to once Slack authorization is complete.
onAuthenticationComplete(authenticationResult: 'authComplete' | 'authFailed') => void;An optional callback function you can pass to this component that will execute upon completion of the authentication flow. Takes one argument of the authentication result for you to handle in your callback.



actionButton*ReactNodeRender a button, either a custom one or the SlackAuthButton, to connect to Slack



slackChannelRecipientObject*ContainerObjectObject ID and collection of the Knock object that will store the channel data of the connected Slack channels.
showConnectedChannelTagsbooleanOptionally show tags of the Slack channels that are connected, defaults to false.

General hooks


Creates an authenticated Knock client.

Returns: Knock instance, authenticated against the user



Exposed under KnockI18nProvider child components.


localestringThe current locale code (defaults to `en`)
t(key: string) => stringA helper function to get the value of a translation from the current `Translations`.

Feed hooks


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


Slack hooks

Exposed under KnockSlackProvider child components.


Builds a Slack authorization URL generator and a disconnect function.


slackClientIdstringThe client ID from your Slack app
redirectUrlstringThe URL to redirect back to after authorizing; should be your own application's URL


buildSlackAuthUrlfunctionFunction to build a valid Slack URL with the necessary scopes
disconnectFromSlackfunctionFunction to disconnect from Slack which revokes the access token and removes it from the tenant in Knock


This hook will continually fetch partial data about Slack channels from a given workspace up to the max limit given.


queryOptionsSlackChannelQueryOptionsAn optional map of params to control the query to the Slack API


dataSlackChannel[]List of partial data about each Slack channel
isLoadingbooleanWhether the channels are loading
refetchfunctionFunction to fetch the channels again


This hook returns partial data about the Slack channels that are present on the given recipient object's channel data. These are the Slack channels that would be notified with this object as a recipient of a workflow.


slackChannelsRecipientObjectContainerObjectThe object that holds connected Slack channesl as channel data


dataSlackChannelConnection[]List of data about the connected Slack channels
loadingbooleanWhether the channels are loading
errorstringError message if something went wrong; otherwise null
updateConnectedChannels(connectedChannels: SlackChannelConnection[]) => void;Function to set the connected channels. Updates all connected channels for the object, does not add to the current ones.
updatingbooleanWhether the channels are currently being set



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.