Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Sending Messages to the Lightning Container Component
The Lightning-container NPM module provides methods to send and receive messages between your JavaScript app and the Lightning container component. You can see the lightning-container module on the NPM website.
1import LCC from 'lightning-container';lightning-container must also be listed as a dependency in your app’s package.json file.
1sendMessage() {
2 LCC.sendMessage({name: "General", value: this.state.messageToSend});
3}This code, part of the static resource, sends a message as an object containing a name and a value, which is user-defined.
When the app receives a message, it’s handled by the function mounted by the addMessageHandler() method. In a React app, functions must be mounted to be part of the document-object model and rendered in the output.
The lightning-container module provides similar methods for defining a function to handle errors in the messaging framework. For more information, see lightning:container NPM Module Reference