React library API reference

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

KnockFeedProvider

The top level feed provider that connects to Knock with the given API key, authenticates a user, and then connects to a feed for that user.

Props

Accepts KnockFeedProviderProps:

apiKeystring*The public API key for the environment
userIdstring*The authenticated user to retrieve a feed for
userTokenstringTODO
feedIdstringA JWT for the authenticated user to verify their identity with, signed with the private key provided in the Knock dashboard
hoststringA custom API host for Knock
defaultFeedOptionsFeedClientOptionsSet defaults for `tenant`, `source`, or `archived` to scope all subsequent feed queries
colorModeColorModeSets the theme as either light or dark mode (defaults to light).
rootlessbooleanWhen set as false, doesn't wrap the children in a `<KnockFeedContainer>`

Hooks

The KnockFeedProvider exposes a useKnockFeed hook for all child components which can be used. The hook returns the following as an object (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

NotificationFeed

Props

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`.
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.

NotificationFeedPopover

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

Props

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`).

NotificationCell

Props

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.

NotificationIconButton

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

Props

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

Button

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

Props

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.

ButtonGroup

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

Props

children*ReactNodeOne or more `Button` components

Hooks

The following hooks are exposed so that you can build headless in-app experiences, without rendering components.

useAuthenticatedKnockClient

Creates an authenticated Knock client.

Returns: Knock instance, authenticated against the user

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.