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.
import LCC from 'lightning-container';
lightning-container must also be listed as a dependency in your app’s package.json file.
sendMessage() { LCC.sendMessage({name: "General", value: this.state.messageToSend}); }
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