Skip to main content

Threaded Comments Props

Threaded comments follow a minimal props philosophy. They work with a single prop that identifies the entity and offer optional props for specific needs.
  • React (Web) — one component, ThreadedCommentSection.
  • React Native and Expo — three components that your screen places: ThreadedComments, ThreadedCommentSection and ThreadedCommentInput. See React Native and Expo Components.

Component Import


Props Interface

The examples below use the web component. On React Native and Expo, pass the same props to ThreadedComments.

Entity Identification

Provide one of these to identify which entity the comments belong to:

entity

Type: Entity | undefined | null A complete Entity object.
Use when: You already have the full entity object from useFetchEntity or similar hooks.

entityId

Type: string | undefined | null The Sublay entity’s own id (a UUID), as returned by the SDK and the API.
Use when: You have the entity’s Sublay ID but not the entity object.

foreignId

Type: string | undefined | null Your external/custom ID for the entity. The component finds the Sublay entity that has this foreignId. It creates one only when createIfNotFound is also set.
Use when: You identify the entity by an ID from your own system.

shortId

Type: string | undefined | null A short, human-readable identifier (if you’ve set one on the entity).
Use when: You have the entity’s short ID, for example from a URL.
You only need ONE of these props. Use whichever fits your data model best.

createIfNotFound

Type: boolean — Default: false Used with foreignId. When set, the entity is created the first time the section is shown if no entity with that foreignId exists yet.
Without it, the section only finds an existing entity. When there is none, it shows its “Couldn’t load comments” state instead of the comments. The created entity has no author, so the project’s Who can create entities without an author setting decides who may create it. The default, Everyone, lets any visitor’s section create it. Under Signed-in users only a visitor with no session can’t, and under No one from the client only a service key can (create the entity from your backend first). A refused section shows the same “Couldn’t load comments” state. See Fetch Entity by Foreign ID. It has no effect with entity, entityId or shortId. The other examples on this page identify the entity by entityId.

Optional Props

isVisible

Type: boolean — Default: true React (Web) only. Whether the comment box is shown. When false, the section shows Sort by and the comments, without the box.
On React Native and Expo, the comment box is its own component: to hide it, don’t render ThreadedCommentInput.

highlightedCommentId

Type: string | undefined | null ID of a specific comment to highlight when the section loads. The section opens focused on that comment’s thread — its parent (if it has one) with the highlighted comment marked under it, and their replies — with a View all comments button that switches to the full comment section. If the comment doesn’t exist, the full comment section shows. See Highlighted Comments.
Use cases: Deep-linking from notifications, jumping to a comment via URL param.

theme

Type: 'light' | 'dark' — Default: 'light' Sets the color theme for the entire comment section. On React (Web) it is only for the inline styles variant. On React Native and Expo both variants use it; it goes on ThreadedComments.
Uses the theme prop to conditionally render dark or light colors:

children

Type: React.ReactNode Content shown in place of the “no comments yet” view, when the entity has no comments. On React Native and Expo, this is the children of ThreadedCommentSection; the children of ThreadedComments is your screen.

React Native and Expo Components

On React Native and Expo, threaded comments are three components, installed together by npx @sublay/cli add comments-threaded --ref v8 and all exported from the component’s index.ts. Your screen places them:
The entity above the section scrolls away with the comments, and the comment box stays pinned below the scroll view. Keyboard handling is up to your screen: use KeyboardAvoidingView as above, or the keyboard library your app already uses. Give the scroll view keyboardShouldPersistTaps="handled", so tapping Reply, a vote or Sort by while the keyboard is open works on the first tap instead of only closing the keyboard.

ThreadedComments

Wraps the screen. It takes the entity props, createIfNotFound, highlightedCommentId, theme, and children: your screen, which holds ThreadedCommentSection and ThreadedCommentInput. It holds the state the other two share, and it renders the sheets — Sort by, the comment menu, the menu for your own comment, and the report form — over the view it wraps. That view is an invisible flex: 1 view, so wrap the whole screen to have the sheets cover the screen. The navigation header your navigator draws stays outside it.

ThreadedCommentSection

The Sort by button and the comments. It has no scrolling of its own: put it inside your screen’s ScrollView, so content above it (the entity) scrolls away with the comments. It throws an error when it is rendered outside ThreadedComments.

ThreadedCommentInput

The comment box, with the “Replying to” bar above it. Place it anywhere inside ThreadedComments, typically pinned below the ScrollView. Tapping Reply on a comment focuses it. It never focuses itself when the screen opens. By default, the view around the box has a top border, on the section’s background color. Passing either prop replaces that default.
To hide the comment box, don’t render ThreadedCommentInput. It throws an error when it is rendered outside ThreadedComments.

Complete Examples

Minimal Usage

For a record in your own database, use foreignId with createIfNotFound instead:

With Dark Mode (Inline Styles)


With Highlighted Comment


Full Example (Web)


Full Example (React Native / Expo)


Next Steps

File Structure

Understand component organization

Features

Explore all features

Customization

Customize the component

Installation

Installation guide