Skip to main content

ondata

ondata

type OnDataEvent {
detail: number; // ID of comment's stream
}

onData(ev: OnDataEvent): Promise<Comment[]> | Comment[]

event is triggered to fetch comments data. Use it to load comments based on the stream ID.

Usage

Loading comments through REST helper

<script>
import { RestURL } from "wx-lib-data-provider";
import { Comments } from 'wx-svelte-comments';

const url = new RestURL("https://some.com/api/comments");
</script>

<Comments ondata={v => url.get(v)} />

This example demonstrates how to load comments using the REST helper. The url.get(v) method fetches comments from the specified API.

Converting ID of comment's stream to data

<script>
import { Comments } from 'wx-svelte-comments';

const ondata = (v) => {
return fetch(`/api/comments/${v}`).then(r => r.json());
};
</script>

<Comments value={1} {ondata} />

In this example, the ondata function fetches comments based on the stream ID. It returns a promise that resolves to an array of comments.