Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

lwc reduceErrors showtoast

import { reduceErrors } from "c/ldsUtils"; //Get that component from link

try{
  ///whatever 
} catch{
  	this.errors = reduceErrors(error);
	this.showToast("error", "Whatever title", this.errors)
}  


JS declaration
// - Toaster
	showToast(variant, title, message) {
		// - To use the ShowToastEvent with reduceErrors we have to join the array's values
		if (typeof message === "object") {
			message = message.join('
');
		}

		const event = new ShowToastEvent({
			title: title,
			message: message,
			variant: variant,
			mode: "dismissable"
		});
		this.dispatchEvent(event);
	}
Source by github.com #
 
PREVIOUS NEXT
Tagged: #lwc #reduceErrors #showtoast
ADD COMMENT
Topic
Name
9+8 =