Skip to main content

Events

notification-kit emits typed events for everything that happens — readiness, received notifications, token changes, permission changes, channel changes, and errors. Subscribe with on() (which returns an unsubscribe function) and remove with off().

import { notifications } from 'notification-kit';

const off = notifications.on('notificationReceived', (event) => {
console.log(event.type, event.data);
});

off(); // or: notifications.off('notificationReceived', handler)

Event envelope

Every callback receives a NotificationEvent. The canonical event.type is always the event name, and the original payload is available both spread onto the event and under event.data:

{
id: string, // unique per emission
type: string, // the event name
timestamp: Date,
data: <payload>, // the full original payload
// ...payload fields are also spread on top level
}

The payload spread sets the envelope fields (type, id, timestamp) last, so a payload field accidentally named type cannot clobber the canonical event type.

Event names

EventFired whenKey payload fields
readyinit() completesplatform, capabilities
notificationReceivedpush or local notification arrivespayload, type ('push' | 'local'), platform
notificationActionPerformeda notification is tapped / action runaction, notification, inputValue
notificationSenta send is dispatchedpayload, type
notificationScheduleda local notification is scheduledoptions, type
notificationCancelleda local notification is cancelledid, type
notificationShownan in-app notification is shownoptions, id
channelCreatedan Android channel is createdchannel
channelDeletedan Android channel is deletedchannelId
tokenReceivedgetToken() resolvestoken
tokenRefreshedthe platform rotates the tokentoken
permissionChangedrequestPermission() resolvesgranted, status
subscribedsubscribe(topic) succeedstopic
unsubscribedunsubscribe(topic) succeedstopic
errorany internal errorerror, context

Distinguishing push from local

notificationReceived fires for both push and local notifications. The kind is on the payload envelope, which is why onPush() checks event.data.type === 'push' before forwarding:

notifications.on('notificationReceived', (event) => {
if (event.data?.type === 'push') {
// handle push
} else {
// handle local
}
});

Listener errors are isolated

If one listener throws, the kit logs the error and continues calling the remaining listeners — one bad handler never blocks the others.