emilkowalski / sonner

An opinionated toast component for React.
https://sonner.emilkowal.ski
MIT License
7.67k stars 236 forks source link

Feature request: Custom callable functions #423

Open basickarl opened 1 month ago

basickarl commented 1 month ago

Hi! It would be really nice to make it possible to add custom functions/callbacks to toastProps.

const id = toast.custom(..., {
  customFunctions: {
    hello: ()=> console.info('hi!');
  }
})

const toast.call(id, 'hello'); // would call the custom function

something like this would be great. We want to update the internals of a toast.

emilkowalski commented 1 month ago

Whats your use case?

basickarl commented 1 month ago

So we have a progress bar in one of our custom toasts, we would like to be able to call this function to update the percentage value of the progress bar inside a toast (or do any manipulation to the toast at runtime for custom toasts). I currently have this working but it's hacky DOM manipulation and would prefer to do it via a proper API.