Add a Comment Section to Your Next.js App
A Comments Component for the App Router and Pages Router
Comments need a database, logins, spam filtering, and moderation. You can skip all of that. Install the Hyvor Talk React library, wrap it in a small client component, and drop it into your post page.
Steps to Add Comments to Next.js
You'll need a website ID. Sign up at the Hyvor Talk Console, add your website with your app's domain, and copy the ID from Settings → Website.
Install the React library:
npm install @hyvor/hyvor-talk-reactCreate a client component at
components/Comments.tsx, and replaceYOUR_WEBSITE_IDwith your website ID:'use client'; import { Comments as HyvorComments } from '@hyvor/hyvor-talk-react'; export default function Comments({ pageId }: { pageId: string }) { return <HyvorComments website-id={YOUR_WEBSITE_ID} page-id={pageId} />; }Render it in your post page, for example
app/blog/[slug]/page.tsx. Pass an ID that never changes aspageId.import Comments from '@/components/Comments'; import { getPost } from '@/lib/posts'; export default async function PostPage({ params, }: { params: Promise<{ slug: string }>; }) { const { slug } = await params; const post = await getPost(slug); return ( <article> <h1>{post.title}</h1> <div dangerouslySetInnerHTML={{ __html: post.html }} /> <Comments pageId={post.id} /> </article> ); }Run
npm run devand open a post. The comments load under it.
Using the Pages Router?
There are no Server Components in the Pages Router, so you can skip the wrapper and import the component directly:
import { Comments } from '@hyvor/hyvor-talk-react';
export default function PostPage({ post }) {
return (
<article>
<h1>{post.title}</h1>
<div dangerouslySetInnerHTML={{ __html: post.html }} />
<Comments website-id={YOUR_WEBSITE_ID} page-id={post.id} />
</article>
);
}That's it. For comment counts, events, and more examples, see the React library README and our React guide.
Frequently asked questions
In the App Router, components are Server Components by default. The comments load in the browser, so the component that renders them needs 'use client'. Your page itself can stay a Server Component.
Yes. Comments are fetched in the browser, not at build time, so they work with static export, ISR, and server rendering. New comments show up without a rebuild or revalidation.
Next.js doesn't have plugins for this, but our React library does the same job. Install it with npm and render one component.
An ID that never changes, like the post ID from your CMS or database. The slug works too if you never change it. See page-id.
Yes. With stateless SSO, you sign the user data on the server (a Server Component or Route Handler is a good fit) and pass it to the component. SSO is part of the Business plan.
No database tables, API routes, or moderation queue to build. Replies, notifications, spam filtering, reactions, and moderation tools are already there.
There is. 14 days, no credit card. See the pricing page for plans.