Toast Module

Enhanced way to show toasts

Do you know that there is another way to show toast besides using platformShowToastEvent module? You can use a new toast module.

Do you know that there is another way to show toast besides using platformShowToastEvent module? You can use a new toast module.

Here is a code sample

javascript
import Toast from 'lightning/toast';

export default class ToastDemo extends LightningElement {
    showError() {
        Toast.show(
            {
                label: 'Error Response - {httpErrorDocs}',
                labelLinks: {
                    httpErrorDocs: {
                        url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404',
                        label: 'HTTP 404'
                    }
                },
                message: 'Received error when trying to update order data. Check the details {errorDetails}.',
                messageLinks: {
                    errorDetails: {
                        url: 'https://someurl.example.com',
                        label: 'here'
                    }
                },
                mode: 'dismissable',
                onclose: this.handleErrorToastClosed,
                variant: 'error'
            },
            this
        );
    }

    handleErrorToastClosed() {
        // Do whatever you wish
    }
}

What are the benefits?

Custom links support for the toast title (not only the content).

Ability to specify links both in the index-based ({0}, {1} ... {n}) and

name-based form.

On close action support.

Cleaner invocation?

Text and code were extracted from the original slide. Plain-text version of the whole catalog