#759·sonner

Add ability to hook into method calls for side effects

Author: comatoryCreated May 12, 2026Updated May 12, 2026

I'd like if the library had an API to hook into method calls. Imagine a toast.error is called and I'd like to capture the error via telemetry globally for any instance of that method call. I know I can work around this by:

  • creating a helper function
  • monkey-patching .error

Could we have a global API which would allow me to hook into the methods? Using events would be ok:

javascript
toast.addEventListener('toast_error', (err) => /* call custom code */)
toast.removeEventListener(/* you get the idea */)

or even something like:

javascript
toast.setup({
   onError: (err) => /* call custom code */
})

I'm mentioning the error style of toasts, but I can imagine being able to intercept any kind of event.