Your Own Interface

Composables for Your Own UI ​

When every element of the interface should be your own, the composables give you a thread's state and actions as refs, with none of Comments' markup. useCommentsThread() reads and writes the thread through @verbb/comments-core's thread store, and useCommentForm() posts from a form of your own with the site's spam protection mounted on it. Signing in, retries and errors are still handled for you.

Drawing your own interface means drawing everything the thread would, such as states, permissions and moderation, so start with <CommentsThread> and part overrides unless you need more than they give.

A Discussion of Your Own ​

This draws a post's comments with a vote button each, and a form for a new comment, using the app's CommentsPlugin settings.

vue
<script setup>
import { useCommentForm, useCommentsThread } from '@verbb/comments-vue';

const props = defineProps(['uri']);
const thread = useCommentsThread(() => ({ ownerUri: props.uri }));
const form = useCommentForm({ thread });
const { state, roots } = thread;
const { handleSubmit, fieldErrors, error, posting } = form;

function toggleVote(comment) {
    const vote = state.value.permissions[comment.uid]?.vote ?? null;

    thread.vote(comment.uid, vote === 'upvote' ? null : 'upvote');
}
</script>

<template>
    <p v-if="state.status === 'error'" role="alert">{{ state.error?.message }}</p>
    <p v-else-if="state.status !== 'ready'">Loading comments…</p>
    <section v-else>
        <h2>{{ state.conversation?.commentCount ?? 0 }} comments</h2>

        <form v-if="state.viewer?.canComment" :ref="form.ref" @submit="handleSubmit">
            <textarea name="content" />
            <p v-for="message in fieldErrors.content ?? []" :key="message">{{ message }}</p>
            <p v-if="error" role="alert">{{ error }}</p>
            <button :disabled="posting">Post</button>
        </form>

        <ul>
            <li v-for="comment in roots" :key="comment.uid">
                <strong>{{ comment.author?.name }}</strong> {{ comment.content?.text }}
                <button v-if="comment.interaction" type="button" @click="toggleVote(comment)">▲ {{ comment.interaction.upvotes }}</button>
            </li>
        </ul>
    </section>
</template>

The options are a getter, so a new uri makes a new thread. The Vue starter's second page is a fuller version, with guests' name and email fields, replies, states and Load more.

Bind the form with :ref="form.ref", which hands Vue the ref itself. A string ref="formRef" with formRef taken out of the result works in the browser too, but vue-tsc doesn't count it as a use, so a project checking for unused variables fails its type check.

useCommentsThread() ​

OptionWhat it does
ownerId or ownerUriThe element the comments belong to.
siteId, endpoint and authDefault to the plugin's settings.
sort and limitAs the thread store takes them.
viewerWhether to read the person's own details alongside each page, for votes, permissions and their own pending comments. Defaults to true.
autoLoadWhether to load the thread as soon as the component mounts. Defaults to true. With false, call load() yourself.
fetchA fetch to use instead of the plugin's or the global one.

The options can be a plain object, a ref or a getter, so the thread can follow a route. The store is made in the browser when the component mounts, so a server render has the empty state and nothing is fetched there. A change to the owner, site, endpoint, sort, limit or kind of sign-in makes a new store.

Return Value ​

ResultWhat it is
stateA shallow ref of the thread's state, below, which changes with every load, write and answer.
rootsA computed list of the top-level comments to show, in order.
replies(uid)One comment's loaded replies, in order, which is reactive when called in a template or a computed.
Every actionThe thread store's actions, bound to it, below.
store and clientRefs of @verbb/comments-core's store and client, once the component has mounted in the browser, and null on the server.

State ​

KeyWhat it holds
statusidle, loading, ready or error.
errorWhy the thread couldn't load, as a CommentsRequestError. Errors from actions are thrown to their caller instead.
conversationThe discussion, with its commentCount, whether it's open, the sort options it offers and its closed notice.
commentsEvery loaded comment, keyed by UID, in the data API's shape.
rootsThe UIDs of the top-level comments, in order. selectRoots(state) gives the comments themselves.
next and loadingMoreThe cursor for the next page of top-level comments, and whether it's loading.
repliesEach comment's loaded reply UIDs, total count, next cursor and loading flag, by the comment's UID. selectReplies(state, uid) gives the loaded replies themselves.
viewerWho's reading, with isGuest, name, canComment, isModerator and the rest.
permissionsWhat the person may do with each comment, by UID, such as canReply, canEdit, canVote and their own vote.
moderationFor a moderator, the held and reported counts.
busyActions waiting on the server, such as vote:<uid>, so a control can show it's busy.
unavailableActions the sign-in never allows, such as editing for a guest on another site.
labels and localeThe thread's translated wording and the site's language.
sort and threadVersionThe current sort, and a stamp of the public data the thread was drawn from.

A comment's own replies.items is always empty in the store, because replies holds the order instead.

Actions ​

ActionWhat it does
load()Loads the first page, and the viewer's window alongside it.
loadMore()Loads the next page of top-level comments.
setSort(sort)Changes the sort and loads again from the start.
loadReplies(uid)Loads the next page of one comment's replies.
loadComment(target)Loads one comment and its parents, by UID or { id } from its permalink, for a link to it.
refreshViewer()Reads the viewer again for everything loaded, such as after signing in.
create(input)Posts a comment, or a reply with parentUid.
update(uid, input)Saves an edit to the person's own comment.
delete(uid)Deletes the person's own comment.
vote(uid, vote)Sets a vote, upvote, downvote or null to take it back.
report(uid, { reason, details }) and withdrawReport(uid)Reports a comment, or withdraws the person's report.
follow(following, email)Follows or stops following the discussion. A guest gives an email address.
moderate(uid, action, { reason, note })A moderator's decision, such as approve or remove.

Every action that writes returns the data API's answer and updates the state from it. Starting the same write again while it's in flight, such as a double click on Post, gets the first one's answer rather than sending another. A write that fails throws a CommentsRequestError, with fieldErrors keyed by field for a form to show, and leaves the state as it was.

CommentsRequestError comes from @verbb/comments-core, and Errors lists every code it can carry. Its message is always safe to show the person.

useCommentForm() ​

useCommentForm({ thread }) posts from your own form. Bind its ref to your <form>, so Protect can add its fields and run its checks there, and its handleSubmit to @submit. The spam protection is mounted when someone starts writing, kept fresh while the form is open, and its evidence goes with each post.

The form reads content, guest[name], guest[email], guest[notifyReplies] and fields[handle] from its own fields, or takes them as submit({ content, guest, fields }). After a post it empties the fields the browser holds, keeping a guest's name and email for their next comment. A v-model value is your own state, so empty it yourself when submit() resolves with an answer rather than null. Trying the same comment again after a failure reuses its operation ID, so the server never posts it twice.

Option or resultWhat it is
threadWhat useCommentsThread() returns, or a store.
mode, parentUid and commentUidcreate by default, reply with parentUid, or edit with commentUid.
nonceA Content Security Policy nonce for the spam protection's challenge scripts. Defaults to the plugin's setting.
refA template ref to bind to your <form>.
submit(input) and handleSubmit(event)Posts, resolving with the data API's answer, or null when it was refused.
fieldErrors and errorRefs of why the last post was refused, keyed by field as content, guest.name, guest.email or fields.handle, and a message for the whole form.
postingA ref of whether a post is on its way.
reset()Clears the errors.
js
// A reply form under one comment.
const replyForm = useCommentForm({ thread, mode: 'reply', parentUid: comment.uid });

Listening for Events ​

useCommentsEvent(name, handler) listens for a browser event from any thread on the page while your component is mounted. Pass { instanceId } for one thread, or { target } with a template ref to listen on an element of your own.

js
import { useCommentsEvent } from '@verbb/comments-vue';

useCommentsEvent('comments:comment-created', (event) => {
    analytics.track('Comment posted', { thread: event.detail.instanceId });
});

With { thread }, it hears the events of a thread from useCommentsThread() instead, and the handler gets each event's detail directly, as the thread store emits it.

Last updated: Nov 18, 2026, 12:27 PM