# Store Events

Each store has a few events, which you listen:

* `onMount(store, cb)`: first listener was subscribed with debounce. We recommend to always use `onMount` instead of `onStart + onStop`, because it has a short delay to prevent flickering behavior.
* `onStart(store, cb)`: first listener was subscribed. Low-level method. It is better to use `onMount` for simple lazy stores.
* `onStop(store, cb)`: last listener was unsubscribed. Low-level method. It is better to use `onMount` for simple lazy stores.
* `onSet(store, cb)`: before applying any changes to the store.
* `onNotify(store, cb)`: before notifying store’s listeners about changes.

`onSet` and `onNotify` events has `abort()` function to prevent changes or notification.

```ts
import { onSet } from 'nanostores'

onSet($store, ({ newValue, abort }) => {
  if (!validate(newValue)) {
    abort()
  }
})
```

Event listeners can communicate with `payload.shared` object.

***

*Imported from the [Nano Stores README](https://github.com/nanostores/nanostores/blob/1.5.5/README.md#store-events) for version 1.5.5. Improve this page there.*
