Skip to content

Callbacks

Usage

Any push method to create notifications accepts both onAutoClear and onManualClear methods to execute some code when the notification is removed from the DOM.

Note

A notification can be removed either automatically (onAutoClear, when timeout is reached) or manually (onManualClear, when the user dismisses it or it is programatically cleared).

It's impossible that both callbacks are executed for the same notification.

Static notifications

ts
push.success({
  message: 'Welcome back, you can now access your account.',
  props: {
    myCustomProp: true
  },
  onAutoClear(item) {
    console.log('Auto cleared!')
    console.log(item.message) // 'Welcome back, you can now access your account.'
  },
  onManualClear(item) {
    console.log('Manually cleared!')
    console.log(item.props.myCustomProp) // true
  }
})

Promise-based notifications

ts
const notification = push.promise({
  message: 'Sending message, please hold on...',
  onAutoClear(item) {
    console.log(item.type) // 'promise-resolve'
    console.log(item.message) // 'Your message has been successfully sent.'
  },
  onManualClear(item) {
    console.log(item.type) // 'promise-resolve'
    console.log('Resolved and then closed by user!')
  }
})

notification.resolve('Your message has been successfully sent.')