Skip to content

Blog Article Comment Form API

Feature name: blog-article-comment-form

Api name: BlogArticleCommentFormApi


API used to communicate with the Blog Article Comment Form in order to manage comment form requests on a page.

classDiagram
direction LR
    BlogArticleCommentFormApi --> addComment

    class BlogArticleCommentFormApi {
        addComment(articleId: string, commentProps: TCommentProps) Promise~TResponseStatus~
    }

    BlogArticleCommentFormApi : TResponseStatus 'success' | 'failed'

    link addComment "../methods/add-comment/"

Get API

To get the Blog Article Comment Form API use its name BlogArticleCommentFormApi with the getApi method.

useStorefront(async (storefront) => {
    const blogArticleCommentFormApi = storefront.getApiSync('BlogArticleCommentFormApi');
});

This API is initialized only after blog-article-comment-form webcomponent has been added to the page. Unless you add the webcomponent, you won't be able to fetch the API. If you wish to use the API alone without the webcomponent you can use the registerDynamic method from the Feature System API. Here is an example on how to do it:

useStorefront(async (storefront) => {
    const featureSystemApi = this.getApiSync('FeatureSystemApi');
    await featureSystemApi.registerDynamic('blog-article-comment-form');

    const blogArticleCommentFormApi = storefront.getApiSync('BlogArticleCommentFormApi');
});

Methods

Event Bus events

Methods of this API dispatch the following events with the Event Bus:

Examples

Making a Blog Article Comment Form API call to add a new blog comment.

    useStorefront(async (storefront) => {
        const blogArticleCommentFormApi = storefront.getApiSync('BlogArticleCommentFormApi');

        await blogArticleCommentFormApi.addComment({
            user: 'Author',
            comment: `This is my comment`
        });
    });

Webcomponents reference

Objects Reference

APIs reference