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.
| Prop | Description |
|---|---|
publishableKeyRequiredstring | Your site's Publishable Key (pk_...) from the console. |
apiUrlRequiredstring | Base URL of the Knit API. |
authBaseUrlstring | URL of the sign-in server, only when it differs from apiUrl. |
bffBasePathstring | Path 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 | null | Where Direct mode stores the session token. Pass null to keep it in memory only.Default: localStorage |
clientKnitClient | A client you created yourself, for example with a custom fetch. Takes priority over bffBasePath and tokenStorage. Read only on the first render. |
initialDataKnitSiteBootstrapResponse | null | Site settings and the reader's session fetched on the server, so the first render needs no request. |
onAuthChange() => void | Called after the reader signs in or out. In Next.js, call router.refresh() here to re-render server data. |
markdownComponentsKnitMarkdownComponents | Replaces single Markdown elements (a, img, pre and so on) in posts and comments. |
componentsKnitUIComponents | Replaces 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. |
messagesKnitMessagesOverride | Overrides UI and error texts. Keys you leave out use the English defaults. |
localestring | Locale for dates. When set, the sign-in popup also uses this language.Default: "en-US" |
injectStylesboolean | Injects the default styles as a <style> tag. Turn off when you import @knit/react/styles.css or write all styles yourself.Default: true |
styleNoncestring | Nonce 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.
| Prop | Description |
|---|---|
initialPostsKnitPaginatedResponse<KnitActivePost> | The first page of posts fetched on the server. |
spaceRequiredstring | The 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. |
initialCollectionsKnitCollectionsResponse | Collections fetched on the server, for the filter bar. |
collectionstring | Shows only this collection, and new posts are added to it. |
collectionPrefixstring | Shows every collection under this path, with a filter bar for the sub-collections. |
tagstring | Initial tag filter. |
resolveAutoTags(input: KnitAutoTagInput) => string[] | Automatic tag rules for posts created or edited in this list. Overrides the one on KnitProvider. |
postBasePathstring | Path that post links start with; a post's URL becomes postBasePath/slug. Safe to pass from a Server Component.Default: "/posts" |
getPostHref(slug: string) => string | Builds post URLs yourself. Takes priority over postBasePath; only usable from a Client Component. |
showToolbarboolean | Shows the toolbar with sign-in and the owner's tools.Default: true |
pageSizenumber | Posts per page. |
classNamestring | Added 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).
| Prop | Description |
|---|---|
initialPostRequiredKnitActivePost | The post fetched on the server with getPostBySlug. |
backHrefstring | Where the back link goes, and where the page moves after the post is deleted (unless onDeleted is set).Default: "/posts" |
postBasePathstring | Path that post links start with; a post's URL becomes postBasePath/slug. Safe to pass from a Server Component.Default: "/posts" |
getPostHref(slug: string) => string | Builds post URLs yourself. Takes priority over postBasePath; only usable from a Client Component. |
onSlugChange(nextSlug: string, post: KnitActivePost) => void | Called when the owner changes the post's slug. By default the URL is replaced with the new one. |
onDeleted() => void | Called after the post is deleted. By default the page moves to backHref. |
showCommentsboolean | Shows the comment section under the post, following the post's comment setting.Default: false |
classNamestring | Added to the root element next to Knit's own classes. |
childrenReactNode | Rendered 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.
| Prop | Description |
|---|---|
postRequiredKnitPost | The post the comments belong to. |
maxDepthnumber | How 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 |
refreshKeynumber | Change this value to load the comments again.Default: 0 |
onAuthorClick(author: KnitUserProfile) => void | Called when a commenter's name is clicked, instead of opening the profile. |
onCommentCountChange(count: number) => void | Called when the number of comments changes. |
classNamestring | Added 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:
| Component | Use |
|---|---|
PostEditor | The post editor. Pass children to add inputs for a post type's own fields (Post types). |
CommentComposer, CommentItem | The comment form and a single comment. |
PostCard, EmptyState | A card in the list, and what the list shows when it is empty. |
CollectionPicker | Choosing a collection for a post. |
ProfileModal | A reader's profile, and editing your own. |
ReportModal | Reporting a comment. |
OwnerPanel | The site-management dialog opened by the ⚙ button: settings, moderation (pending replies, reports, blocked readers), notification settings, members and export. |
OwnerAudience | The members tab on its own: list members, add readers who have signed in, remove them. See Spaces and members. |
NotificationBell | The bell with unread badge, list and settings. See Notifications. |
NotificationSettings | The notification settings on their own. See Notifications. |
ImageLightbox | Images shown full-screen. |