@hyvor/hyvor-talk-base
v0.0.6
Published
This library provides types and helper functions for [Hyvor Talk](https://talk.hyvor.com).
Downloads
2,277
Readme
This library provides types and helper functions for Hyvor Talk.
Helpers
addComments(props, container, onEvent)
Adds <hyvor-talk-comments>
(docs) to the given container.
import { addComments } from '@hyvor/hyvor-talk-base';
addComments(
{
'website-id': 1,
'page-id': 'unique-page-id',
},
document.getElementById('comments-container'),
(event, data) => {
console.log(event, data);
}
);
addCommentCounts(props)
Adds the script that registers the <hyvor-talk-comment-count>
custom element to the page. Note that unlike addComments
, this function does not add the element to the page. You need to add <hyvor-talk-comment-count>
elements to the page manually, and then call this function to load the comment counts.
import { addCommentCounts } from '@hyvor/hyvor-talk-base';
addCommentCounts(
{
'website-id': 1,
'page-id': 'unique-page-id',
}
);
Example from our React package:
export function CommentCount(props: CommentCountProps) {
useEffect(() => addCommentCounts(props), []);
return <hyvor-talk-comment-count {...props} />
}
addCommentCounts
function automatically callsloadCommentCounts
ifloading="manual"
is not set.
loadCommentCounts(props)
Loads comment counts from Hyvor Talk servers and updates the <hyvor-talk-comment-count>
elements. See the docs for more information on optimized usage.
import { loadCommentCounts } from '@hyvor/hyvor-talk-base';
loadCommentCounts(
{
'website-id': 1,
}
);