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



Use `Salla.api.component` when browser code needs the store's menus or a set of reviews, for example in a block that loads after the page.
For the first render, read menus with the [`menu` API module](https://docs.salla.dev/twilight/react/api/modules/menu) in a loader instead, so they are in the page from the start.

This module is only on `Salla.api`, not on `Salla` directly: write `Salla.api.component.getMenus()`.

```ts
const { data: header } = await Salla.api.component.getMenus('header');
const { data: reviews } = await Salla.api.component.getReviews({ type: 'products', items: [12, 15], per_page: 5 });
```

## Methods [#methods]

| Method       | Parameters                                    | Returns                              |
| ------------ | --------------------------------------------- | ------------------------------------ |
| `getMenus`   | `'header'` or `'footer'` (default `'header'`) | The menu, in the current language    |
| `getReviews` | `{ type?, items?, per_page? }`                | Reviews. `per_page` is 5 by default. |

`type` picks where the reviews come from:

| `type`                   | `items`                             |
| ------------------------ | ----------------------------------- |
| `all` (default), `store` | Not needed                          |
| `products`, `categories` | An array of product or category ids |
| `json`                   | Needed too: the items to show       |

## Events [#events]

| Event                                                            | Fires when   | Arguments         |
| ---------------------------------------------------------------- | ------------ | ----------------- |
| `component::menus.fetched` / `component::menus.fetch.failed`     | `getMenus`   | response or error |
| `component::reviews.fetched` / `component::reviews.fetch.failed` | `getReviews` | response or error |

The helpers are `Salla.event.component.onMenuFetched` and `onReviewsFetched`, with their `off...` pairs.

## Gotchas [#gotchas]

* `getReviews` checks its input before sending: an unknown `type`, or `products` without an array of ids, rejects at once.
* Old Twig examples call `Salla.event.component.reviewsFetched(fn)`. That fires the event instead of listening to it. Use `onReviewsFetched`.

## See also [#see-also]

* [`menu` API module](https://docs.salla.dev/twilight/react/api/modules/menu)
* [Header and footer](https://docs.salla.dev/twilight/react/layouts/header-and-footer)
