Skip to main content

Type Alias: UsePushNotificationsOptions

UsePushNotificationsOptions = object

Defined in: usePushNotifications.ts:15

Properties​

enabled?​

optional enabled?: boolean

Defined in: usePushNotifications.ts:37

Set to false where no service worker is registered (local dev), and the hook reports unsupported. Defaults to true.


onError?​

optional onError?: (error) => void

Defined in: usePushNotifications.ts:32

Called with every unexpected error, for error tracking.

Parameters​

ParameterType
errorError

Returns​

void


onSubscribe​

onSubscribe: (subscription) => Promise<void>

Defined in: usePushNotifications.ts:24

Persists a new subscription. A rejection unsubscribes the browser again, so the browser and the server never disagree.

Parameters​

ParameterType
subscriptionPushSubscriptionData

Returns​

Promise<void>


onUnsubscribe​

onUnsubscribe: (subscription) => Promise<void>

Defined in: usePushNotifications.ts:28

Removes a subscription before the browser drops it.

Parameters​

ParameterType
subscription{ endpoint: string; }
subscription.endpointstring

Returns​

Promise<void>


syncExisting?​

optional syncExisting?: boolean

Defined in: usePushNotifications.ts:45

When true, a subscription the browser already holds is handed to onSubscribe again on mount, so the app stores it under whoever is signed in now: a browser outlives sessions, and another account may have subscribed it. isSubscribed turns true only once that resolves. Defaults to false.


vapidPublicKey​

vapidPublicKey: string | undefined

Defined in: usePushNotifications.ts:19

The server's VAPID public key, base64url encoded.