Your Svelte App, Now With a Comment Section
Svelte Components for Comments, Reactions, and Ratings
Add a complete comment section to your Svelte or SvelteKit app with one component. Replies, notifications, spam filtering, and moderation are already done for you.
Steps to Add Comments to Svelte
The Hyvor Talk Svelte library wraps our embeds as Svelte components. 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 library:
npm install @hyvor/hyvor-talk-svelteAdd the
<Comments>component where you want the comments. Its props are the same as the embed attributes.<script> import { Comments } from '@hyvor/hyvor-talk-svelte'; export let post; </script> <article> <h1>{post.title}</h1> {@html post.content} </article> <Comments website-id={YOUR_WEBSITE_ID} page-id={post.id} />Replace
YOUR_WEBSITE_IDwith your website ID, and pass a stable value like the post ID aspage-id.
Show comment counts
<CommentCount> shows the number of comments on a page. Add the components,
then call CommentCounts.load() in onMount.
<script>
import { CommentCount } from '@hyvor/hyvor-talk-svelte';
import { CommentCounts } from '@hyvor/hyvor-talk-base';
import { onMount } from 'svelte';
export let posts;
onMount(() => {
CommentCounts.load({
'website-id': YOUR_WEBSITE_ID,
});
});
</script>
{#each posts as post}
<a href={post.url}>
{post.title} (<CommentCount page-id={post.id} />)
</a>
{/each}Events and the API
Listen to events with the on: directive.
Bind element to reach the web component and call its API methods.
<script>
import { Comments } from '@hyvor/hyvor-talk-svelte';
let element;
function onLoad() {
console.log(element.api.page());
}
</script>
<Comments
website-id={YOUR_WEBSITE_ID}
page-id={post.id}
bind:element
on:loaded={onLoad}
on:comment:published={() => console.log('Comment published')}
/>That's it. Start your dev server and the comments load where you placed the component. More examples are in the Svelte library README.
Frequently asked questions
Very little. Import Comments from @hyvor/hyvor-talk-svelte and add the component with your website ID and a page ID. The library loads everything else.
Either works, but the Svelte library is nicer. It gives you real Svelte components that wrap the <hyvor-talk-comments> web component, so you get props, bind:, and on: events like with any other component.
A comment system needs storage, replies, notifications, spam filtering, moderation, and logins before it is useful. A commenting platform for Svelte covers all of it, and your app stays small because the comments load from a single script.
Yes, it's a regular Svelte component, so you add it to your SvelteKit pages the same way. Use the post slug or ID from your load data as the page-id.
One that stays the same for the life of the page, like a database ID or slug. Each page-id loads its own thread. See page-id.
Yes. Use bind:element to get the underlying web component, then call its API methods once the loaded event fires.
Yes. The same component can show reactions or star ratings above the comments. Change the default in the Console, or per page with embed settings.
No. You get a 14-day free trial without a credit card. See pricing for plans.