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



Read this when browser code needs a value the SDK holds, such as the store id, the current page or whether the customer is logged in.

When the engine starts the SDK, it hands it the store's settings, the customer and the current page. `Salla.config` keeps them.
In React components, read the same data from the hooks first: [`useStore`](https://docs.salla.dev/twilight/react/hooks/use-store), [`useTheme`](https://docs.salla.dev/twilight/react/hooks/use-theme) and [`useUser`](https://docs.salla.dev/twilight/react/hooks/use-user).
Use `Salla.config` in SDK code, in event handlers, and for values the hooks do not expose.

## Read a value [#read-a-value]

Pass a key. Use dots for nested values, and an optional default:

```ts
Salla.config.get('store.id');                 // 1305146709
Salla.config.get('page.slug');                // 'product.single'
Salla.config.get('user.currency_code', 'SAR');
Salla.config.all();                           // the whole object
```

Some keys you will use:

| Key                                        | Holds                                                                 |
| ------------------------------------------ | --------------------------------------------------------------------- |
| `store.id`, `store.url`                    | The store's id and address                                            |
| `store.features`                           | Feature flags the store has on, such as `'loyalty-system'`            |
| `user.id`, `user.type`                     | The customer, and `'user'` when logged in                             |
| `user.currency_code`, `user.language_code` | The customer's chosen currency and language                           |
| `page.slug`, `page.id`                     | The kind of page and its product, category or order id                |
| `currencies`                               | The store's currencies by code, each with `code`, `name` and `symbol` |
| `theme.is_rtl`                             | Whether the page is right-to-left                                     |

The engine sets `page` again after each navigation in the browser, from the `page` your route's loader returns. The built-in routes all return one, so there `page.slug` matches the page on screen.

## Check the customer [#check-the-customer]

| Method                   | Returns                               |
| ------------------------ | ------------------------------------- |
| `Salla.config.isUser()`  | `true` when the customer is logged in |
| `Salla.config.isGuest()` | `true` when they are not              |

Many SDK methods need a logged-in customer. The wishlist methods, for example, open the login popup for a guest instead of sending the request.

## Currencies and languages [#currencies-and-languages]

| Method                         | Returns                                                                             |
| ------------------------------ | ----------------------------------------------------------------------------------- |
| `Salla.config.currency(code?)` | One currency (`code`, `name`, `symbol`). Without a code, the customer's chosen one. |
| `Salla.config.currencies()`    | A promise of all currencies by code. It loads the list from the store once.         |
| `Salla.config.languages()`     | A promise of the store's languages, each with `code`, `url` and `is_rtl`.           |

To show prices, use [`useMoney`](https://docs.salla.dev/twilight/react/hooks/use-money) in components. It formats with the right currency for you.

## Change a value [#change-a-value]

`Salla.config.set(key, value)` changes one value, with dots for nested keys:

```ts
Salla.config.set('debug', true);  // the SDK logs what it does to the browser console
```

To change several top-level values at once, use `Salla.config.merge({ ... })`.

## Gotchas [#gotchas]

* `set` takes a key and a value. `Salla.config.set({ debug: true })` throws: pass an object to `merge` instead.
* `set` changes only the SDK's copy. Your React state and the hooks do not see it.
* For a top-level key such as `'debug'`, `get` also returns the default when the value is empty (`0`, `''`, `false`). A dotted key returns the default only when the value is missing.
* `currencies()` and `languages()` load the list once per page. Later calls return the same list.

## See also [#see-also]

* [`useStore`](https://docs.salla.dev/twilight/react/hooks/use-store) and [`useUser`](https://docs.salla.dev/twilight/react/hooks/use-user)
* [Storage](https://docs.salla.dev/twilight/react/sdk/storage)
* [Overview](https://docs.salla.dev/twilight/react/sdk)
