---
schema_version: "1"
id: 564efa40e75eadec90dd8295aba5fcaf349abfc9990aaf8aee346f57066a18ed
title: addMessageHandler()
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/aura-platform/guides/aura/container/container-npm-addmessagehandler.md
canonical_url: https://developer.salesforce.com/docs/platform/aura-platform/guide/container-npm-addmessagehandler.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 9f3259219f097e83794c2338e6252588b3e69f5b984ea2b99337cc60ea35e81b
products:
  - Lightning Aura Components Developer Guide
  - Platform Developer Content
---

# addMessageHandler()

Mounts a message handling function, used to handle messages sent from the Aura 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.

```javascript
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
  }
}
```

## Arguments

| Name                              | Type     | Description                                                      |
| --------------------------------- | -------- | ---------------------------------------------------------------- |
| `handler: (userMsg: any) => void` | function | The function that handles messages sent from the Aura component. |

## Response

None.
