Skip to main content

Quick Start Guide

This guide installs a Sublay component into your project and renders it: a comment section bound to a Sublay entity, or the notifications bell. It focuses on the components. For a whole app built on Sublay — sign-up, creating and listing entities, comments and reactions — start with Build your first Sublay app.

Before You Begin

  • ✅ Node.js 20.5+ installed
  • ✅ A React, React Native, or Expo project
  • ✅ A Sublay project with the entities and comments bundles installed, plus reactions (votes and likes) and moderation (the report button files reports through it). See Bundles.

Step 1: Initialize the CLI

Run the init command in your project directory:

Answer the prompts:

1

Select Platform

2

Choose Styling

  • Select Tailwind CSS if you use Tailwind
  • Select Inline Styles otherwise
3

Set Component Path

Press Enter to use the default, or type a custom path.
The CLI creates a sublay.json configuration file and checks for required dependencies.

Step 2: Install Dependencies (if needed)

The CLI will prompt you to install these automatically if they’re missing.

Step 3: Add a Component

Pick a component and a language to get the command:
  • Threaded comments — Reddit-style discussions with unlimited nesting, upvote/downvote, threading lines, and collapsible threads.
  • Social comments — Instagram-style comments with single-level nesting, heart/like system, and Top/New/Old sorting.
  • Notifications — a notification bell with a dropdown of the user’s notifications.
The language applies to the comment components; see Languages & Right-to-Left. --ref v8 reads the component from the v8 branch of the registry, where the v8 components live. The CLI copies about 40 source files into your project and shows a usage example. It also checks your package.json for the third-party packages the component needs (the Giphy packages for the GIF picker, for example) and offers to install the ones that are missing.

Step 4: Set Up SublayProvider

Wrap your app (or the relevant section) with SublayProvider:
To post, reply or vote, a user must be signed in. Sublay’s built-in auth handles sign-up and sign-in for you; the complete example below adds a sign-in form.
If your app already has its own authentication, see External Authentication to connect it to Sublay.

Step 5: Use the Component

Bind the comment section to a Sublay entity: pass its entityId, or the entity object itself. Entities are what your users create — with useCreateEntity, for example — and what you load with useEntityList or EntityProvider.
On React Native and Expo, threaded comments are three components that your screen places: ThreadedComments wraps the screen, ThreadedCommentSection (Sort by and the comments) goes in its ScrollView, and ThreadedCommentInput (the comment box) is pinned below:
That’s it! Sublay stores each comment against the entity, and the section loads, posts, votes and reports through the SDK.

Complete Example

A working page: a sign-in form, using built-in auth, and a list of the newest entities, each with its own comment section. Users sign up with signUpWithEmailAndPassword the same way. Sublay doesn’t require a username, but the comment components do: as installed, they stop a user without one from posting, replying, voting or reporting. Pass a username at sign-up, or change usernameRequiredCallback in hooks/use-threaded-comments.tsx (or hooks/use-social-comments.tsx).
For social comments, import SocialCommentSection from ./components/comments-social and use it the same way. To let users create the entities in the list, see Build your first Sublay app.

Attach Comments to Records You Already Have

If what users comment on lives in your own database — an article in your CMS, a product in your catalog — you don’t need to create its entity yourself. Pass your record’s ID as foreignId, with createIfNotFound, and the section creates the entity the first time it loads and finds it by that ID afterwards:
On React Native and Expo, pass the same props to ThreadedComments.
createIfNotFound creates the record’s entity the first time its comment section loads. That entity has no author, and the project’s Who can create entities without an author setting decides who may create one. The default, Everyone, lets any visitor’s section create it; under Signed-in users only or No one from the client, see createIfNotFound for threaded and social comments.
See Link entities to records you already have.

What Gets Installed

All files are editable TypeScript/TSX, documented with inline comments, and committed to your repo. That includes the files in shared/, the presentational pieces the component is built from.

Troubleshooting

Make sure the import path matches your paths.components in sublay.json:
  1. Check that <SublayProvider> wraps the component
  2. Verify projectId is correctly set
  3. Check the browser console for errors
Ensure your tsconfig.json includes the components directory:
React: make Tailwind’s dark mode follow a dark class (Tailwind CSS 3: darkMode: 'class' in tailwind.config.js; Tailwind CSS 4: @custom-variant dark (&:where(.dark, .dark *)); in your CSS), and add a dark class to a parent element:
React Native and Expo: pass theme="dark" to the component. There is no Tailwind dark mode setup.

Next Steps

Props API

Learn about available props and options

File Structure

Understand the installed file organization

Customization

Customize colors, layout, and functionality

Styling Variants

Inline styles vs Tailwind CSS