# Events

> Run your code when the unread count changes or the contact closes the widget.

```ts
Iris.on(event: "unread" | "close", listener: (count?: number) => void): void
```

## unread

The listener runs once with the current count, then on every change. Use it to show a badge on your own button when the launcher is hidden.

```js title="app.js"
const badge = document.querySelector("#help-badge");

Iris.on("unread", (count) => {
  badge.textContent = String(count);
  badge.hidden = !count;
});
```

## close

The listener runs each time the contact closes the widget: with the close button, the launcher or the Escape key. `Iris.close()` does not run it. Use it to hide your own view of the widget, such as the WebView of a [React Native app](/guides/react-native/).

```js title="app.js"
Iris.on("close", () => {
  helpPanel.hidden = true;
});
```

## Console warnings

| Message | What happened | Fix |
| --- | --- | --- |
| `Iris: on ignored the listener, because the event is not "unread" or "close", or the listener is not a function.` | The event name is not `"unread"` or `"close"`, or the listener is not a function. | Pass `"unread"` or `"close"` and a function. See [Events](/reference/events/). |
