addMessageHandler()

Mounts a message handling function, used to handle messages sent from the Lightning component to the framed JavaScript app.

Sample

Used within a JavaScript app uploaded as a static resource and referenced by lightning:container, this example mounts a message handling function. In a React app, functions must be mounted to be part of the document-object model and rendered in the output.
componentDidMount() {
    LCC.addMessageHandler(this.onMessage);
}

onMessage(msg) {
  let name = msg.name;
  if (name === "General") {
    let value = msg.value;
    this.setState({messageReceived: value});
  }
  else if (name === "Foo") {
    // A different response
  }
}

You can view and download this example in the Developerforce Github Repository.

Arguments

Name Type Description
handler: (userMsg: any) => void function The function that handles messages sent from the Lightning component.

Response

None.