Components

Props of KnitProvider and of the default UI in @knit/react/ui. Every component must be rendered inside a KnitProvider.

KnitProvider

Connects its children to your site on Knit and holds the session, texts and customizations. Import it from @knit/react.

PropDescription
publishableKeyRequiredstringYour site's Publishable Key (pk_...) from the console.
apiUrlRequiredstringBase URL of the Knit API.
authBaseUrlstringURL of the sign-in server, only when it differs from apiUrl.
bffBasePathstringPath of the route handler on your site (for example "/api/knit"). When set, Knit runs in BFF mode and keeps the session in an HttpOnly cookie; otherwise it talks to the API directly.
tokenStorageKnitTokenStorage | nullWhere Direct mode stores the session token. Pass null to keep it in memory only.Default: localStorage
clientKnitClientA client you created yourself, for example with a custom fetch. Takes priority over bffBasePath and tokenStorage. Read only on the first render.
initialDataKnitSiteBootstrapResponse | nullSite settings and the reader's session fetched on the server, so the first render needs no request.
onAuthChange() => voidCalled after the reader signs in or out. In Next.js, call router.refresh() here to re-render server data.
markdownComponentsKnitMarkdownComponentsReplaces single Markdown elements (a, img, pre and so on) in posts and comments.
componentsKnitUIComponentsReplaces parts of the default UI: PostCard, PostEditor, MarkdownEditor, EmptyState and CommentItem.
resolveAutoTags(input: KnitAutoTagInput) => string[]Decides automatic tags from a post's content when it is created or edited.
messagesKnitMessagesOverrideOverrides UI and error texts. Keys you leave out use the English defaults.
localestringLocale for dates. When set, the sign-in popup also uses this language.Default: "en-US"
injectStylesbooleanInjects the default styles as a <style> tag. Turn off when you import @knit/react/styles.css or write all styles yourself.Default: true
styleNoncestringNonce for the injected <style> tag under a strict Content Security Policy.

PostList

A list of posts with filters, pagination, sign-in, and the owner's tools to create, edit and delete posts.

PropDescription
initialPostsKnitPaginatedResponse<KnitActivePost>The first page of posts fetched on the server.
spaceRequiredstringThe key of the space to show. Spaces are created in the Console; a new site starts with a public space named "default". There is no fallback when it is omitted.
initialCollectionsKnitCollectionsResponseCollections fetched on the server, for the filter bar.
collectionstringShows only this collection, and new posts are added to it.
collectionPrefixstringShows every collection under this path, with a filter bar for the sub-collections.
tagstringInitial tag filter.
resolveAutoTags(input: KnitAutoTagInput) => string[]Automatic tag rules for posts created or edited in this list. Overrides the one on KnitProvider.
postBasePathstringPath that post links start with; a post's URL becomes postBasePath/slug. Safe to pass from a Server Component.Default: "/posts"
getPostHref(slug: string) => stringBuilds post URLs yourself. Takes priority over postBasePath; only usable from a Client Component.
showToolbarbooleanShows the toolbar with sign-in and the owner's tools.Default: true
pageSizenumberPosts per page.
classNamestringAdded to the root element next to Knit's own classes.

PostDetail

One post, with the owner's tools to edit and delete it. Fetch the post on the server and pass it as initialPost (see Next.js).

PropDescription
initialPostRequiredKnitActivePostThe post fetched on the server with getPostBySlug.
backHrefstringWhere the back link goes, and where the page moves after the post is deleted (unless onDeleted is set).Default: "/posts"
postBasePathstringPath that post links start with; a post's URL becomes postBasePath/slug. Safe to pass from a Server Component.Default: "/posts"
getPostHref(slug: string) => stringBuilds post URLs yourself. Takes priority over postBasePath; only usable from a Client Component.
onSlugChange(nextSlug: string, post: KnitActivePost) => voidCalled when the owner changes the post's slug. By default the URL is replaced with the new one.
onDeleted() => voidCalled after the post is deleted. By default the page moves to backHref.
showCommentsbooleanShows the comment section under the post, following the post's comment setting.Default: false
classNamestringAdded to the root element next to Knit's own classes.
childrenReactNodeRendered under the post, for example your own comment section.

CommentSection

Comments and replies for a post. PostDetail renders one for you with showComments; use CommentSection directly when you place comments yourself.

PropDescription
postRequiredKnitPostThe post the comments belong to.
maxDepthnumberHow deep replies nest. The effective depth is the smaller of this and the space's reply depth (set in the Owner panel); deeper replies are shown flat at that level, and 0 makes a flat list.Default: space setting
refreshKeynumberChange this value to load the comments again.Default: 0
onAuthorClick(author: KnitUserProfile) => voidCalled when a commenter's name is clicked, instead of opening the profile.
onCommentCountChange(count: number) => voidCalled when the number of comments changes.
classNamestringAdded to the root element next to Knit's own classes.

Reply policy

Each post has a reply policy: open (shown at once), approval (shown after a site admin approves) or closed. A space's default policy for new posts and its reply depth are set in the Owner panel (the ⚙ button), under Settings. Replies waiting for approval are visible only to their author and to site admins, and are approved from Moderation → Pending. One exception: when a pending reply already has published replies under it (for example, its author edited it after approval), other readers see an “awaiting approval” placeholder without its text or author. The API returns that node with isDeleted: true and status: "pending"; check status in a custom CommentItem to tell it apart from a deleted one.

Owner panel

Place OwnerPanel inside SiteAdmin.Root. PostList and PostDetail already include it. On a page with only CommentSection, add OwnerPanel yourself if you use the ⚙ button or useKnitOwnerPanel().open() there. If several are on a page, only the first one mounted renders, with its props.

Other components

These are opened by the components above, and are exported for when you build your own screens:

ComponentUse
PostEditorThe post editor. Pass children to add inputs for a post type's own fields (Post types).
CommentComposer, CommentItemThe comment form and a single comment.
PostCard, EmptyStateA card in the list, and what the list shows when it is empty.
CollectionPickerChoosing a collection for a post.
ProfileModalA reader's profile, and editing your own.
ReportModalReporting a comment.
OwnerPanelThe site-management dialog opened by the ⚙ button: settings, moderation (pending replies, reports, blocked readers), notification settings, members and export.
OwnerAudienceThe members tab on its own: list members, add readers who have signed in, remove them. See Spaces and members.
NotificationBellThe bell with unread badge, list and settings. See Notifications.
NotificationSettingsThe notification settings on their own. See Notifications.
ImageLightboxImages shown full-screen.