9

According to this official documentation the platform-show-toast-event component/event is unsupported in LWR site.

According to this official sample LWR site a showToast event is utilized (see line 76 of footerMenuItem.js)

These are conflicting each other and I'm wondering whether showToast can be used in LWR?

1
  • 6
    show-toast-event is currently not supported in LWR. I'll talk to the developer and get the sample app updated. If there's a reason why it's included, I'll let you know that too. Thanks for flagging. Aug 5, 2021 at 7:03

2 Answers 2

2

Note that from the Summer '23 release, you can use https://help.salesforce.com/s/articleView?id=release-notes.rn_lwc_toastcontainer.htm&language=en_US&release=246&type=5

1

As a workaround solution, one can try to detect that ShowToastEvent is not available and use alert or other means to display toasts when it is not available

import { ShowToastEvent } from 'lightning/platformShowToastEvent';
export default class Component extends LightningElement {
    connectedCallback() {
        if (typeof ShowToastEvent !== 'undefined') {
            this.dispatchEvent(
                new ShowToastEvent({
                    'variant': 'error',
                    "title": "Error",
                    "message": 'Connected'
                })
            );
        } else {
            alert('Connected');
        }
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .