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



Read this when you want to show a short message through the SDK, or stop the SDK from showing one.

`Salla.notify` is how the SDK tells the customer what happened. After a request, it shows the message from the response:
a success after a coupon is applied, an error when a product is out of stock.

## The engine draws the messages [#the-engine-draws-the-messages]

On its own, the SDK shows messages with the browser's `alert()`. The engine replaces that: its `Toaster` shows them as [toasts](https://docs.salla.dev/twilight/react/components/toast),
in the same style as your own `toast()` calls. Inside the Salla mobile app, the engine hands them to the app instead.

So in a React theme you do not set anything up. Messages from SDK calls already look right.

## Show a message [#show-a-message]

| Method                                    | Shows                                                   |
| ----------------------------------------- | ------------------------------------------------------- |
| `Salla.notify.success(message, data?)`    | A success message                                       |
| `Salla.notify.error(message, data?)`      | An error message                                        |
| `Salla.notify.info(message, data?)`       | A neutral message                                       |
| `Salla.notify.fire(message, type, data?)` | A message of `type`: `'success'`, `'error'` or `'info'` |

`Salla.success` and `Salla.error` are short names for the first two.

```ts
Salla.notify.error(Salla.lang.get('common.messages.required_fields'));
```

In your own components, call [`toast`](https://docs.salla.dev/twilight/react/components/toast) directly instead. It has more options, such as a loading state.

## Call without a message [#call-without-a-message]

Some calls run in the background, and their message would only confuse the customer. Wrap them in `Salla.api.withoutNotifier`:

```ts
const details = await Salla.api.withoutNotifier(() => Salla.cart.details());
```

No success or error message is shown while the wrapped call runs. Events still fire, and the promise still rejects on failure.

## Use your own notifier [#use-your-own-notifier]

`Salla.notify.setNotifier(fn)` replaces what draws the messages. The function receives the message, the type and the extra data:

```ts
Salla.notify.setNotifier((message, type, data) => {
  // draw the message your own way
});
```

In a React theme the engine's `Toaster` sets the notifier when it mounts, and sets an empty one when it unmounts. A notifier you set earlier is replaced, so let the `Toaster` draw SDK messages.

## Gotchas [#gotchas]

* Do not add a toast of your own after an SDK call that already sends a message, or the customer sees two.
* `withoutNotifier` mutes every SDK message on the page until the wrapped call finishes, including messages from other calls made at the same time.
* An error that lists invalid fields is shown as one message with one line per field.

## See also [#see-also]

* [`toast`](https://docs.salla.dev/twilight/react/components/toast)
* [Overview](https://docs.salla.dev/twilight/react/sdk)
