# 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.
