# Smootify.on()

> listens to an event; `replay` also calls the handler with the last payload of one that already happened. Returns the unsubscribe.

Status: Ready (Smootify 2.0)  
URL: https://www.smootify.io/docs/reference/api/methods/on  
Updated: 2026-10-13

listens to an event; `replay` also calls the handler with the last payload of one that already happened. Returns the unsubscribe. New in 2.0.

```ts
on<N extends SmootifyEventName | SmootifyShortEventName>( name: N, handler: SmootifyEventHandler<N>, options?: { replay?: boolean }, ): () => void
```

## Types

### SmootifyEventName

```ts
export type SmootifyEventName = keyof SmootifyEventMap;
```

### SmootifyShortEventName

```ts
/** A `smootify:` event by its name alone: `cart_updated`, `wishlist:changed_product`. */
export type SmootifyShortEventName = {
  [K in SmootifyEventName]: K extends `smootify:${infer Short}` ? Short : never;
}[SmootifyEventName];
```

### SmootifyEventHandler

```ts
export type SmootifyEventHandler<N extends SmootifyEventName | SmootifyShortEventName> = (
  payload: SmootifyEventMap[FullEventName<N>],
) => void;
```
