Skip to content

feat: pass ToastShowParams to onShow callback #587

Description

@yagiz2000

Problem

Currently, the onShow callback has the signature () => void, which means it doesn't receive any information about the toast that was just shown.

This makes it difficult to implement common use cases like sending analytics events when a toast is displayed. For example, if you want to track which toast types are being shown to users, you have to maintain external state or use workarounds.

Proposed Solution

Change the onShow signature from:

onShow?: () => void;

to:

onShow?: (params: ToastShowParams) => void;

This applies to both ToastOptions and ToastProps.

The onShow() call in useToast.ts would pass through the params that were given to show():

// before
onShow();

// after
onShow(params);

Use Case

<Toast
  onShow={(params) => {
    analytics.track('toast_shown', {
      type: params.type,
      text1: params.text1,
    });
  }}
/>

or per-toast:

Toast.show({
  type: 'error',
  text1: 'Payment failed',
  onShow: (params) => {
    analytics.track('toast_shown', { type: params.type });
  },
});

Breaking Changes

This is backwards compatible — existing onShow: () => {} callbacks will continue to work since the extra parameter is simply ignored.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions