# comment (https://docs.salla.dev/twilight/react/sdk/comment)



Use `Salla.comment` for comments the customer writes on a product, a page or a blog article. The `salla-comments` web component lists and adds comments for you: see [`salla-comments`](https://docs.salla.dev/twilight/react/web-components/salla-comments).

```ts
await Salla.comment.add({ type: 'product', id: 85214, comment: 'The price is good' });

const { data } = await Salla.comment.getComments('product', 85214, 1, 10);
```

## Methods [#methods]

| Method          | Parameters                                            | Does                                                            |
| --------------- | ----------------------------------------------------- | --------------------------------------------------------------- |
| `add`           | `{ type, id, comment }`                               | Adds a comment. `type` is `'product'`, `'page'` or `'blog'`.    |
| `getComments`   | `type, id, page?, perPage?, sort?, customerId?`       | Lists comments on one item, or on several when `id` is an array |
| `fetchComments` | `{ type, ids, page?, per_page?, sort?, customerId? }` | The same, with one object                                       |

`page` starts at 1 and `perPage` is 5 by default. Pass `customerId` to also ask for that customer's private comments.

To add a comment from a form, see [Forms](https://docs.salla.dev/twilight/react/sdk/forms): `Salla.form.submit('comment.add', e.nativeEvent)` reads `type`, `id` and `comment` from the fields.

## Events [#events]

| Event                                         | Fires when                     | Arguments                      |
| --------------------------------------------- | ------------------------------ | ------------------------------ |
| `comment::added` / `comment::addition.failed` | `add`                          | response or error, item id     |
| `comment::fetched` / `comment::fetch.failed`  | `getComments`, `fetchComments` | response or error, the request |

## Gotchas [#gotchas]

* Adding a comment needs a logged-in customer.
* `getProductComments` and `getPageComments` from the old Twig docs no longer exist, although the SDK's types still list them. Use `getComments('product', id)` and `getComments('page', id)`.
* `add` and `fetchComments` also accept the plural type (`'products'`, `'pages'`, `'blogs'`). `getComments` takes the singular only, because it adds the `s` itself.

## See also [#see-also]

* [Rating](https://docs.salla.dev/twilight/react/sdk/rating)
* [Forms](https://docs.salla.dev/twilight/react/sdk/forms)
