---
schema_version: "1"
id: c03a57a56e0ca09d488449b191137f6a07bf9fcbfbc0fc4ce297a85b3fa548ec
title: Sending Messages to the Lightning Container Component
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/aura-platform/guides/aura/container/container-messages-npm.md
canonical_url: https://developer.salesforce.com/docs/platform/aura-platform/guide/container-messages-npm.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 3dd5c4ccc06714336b355a551e1cf25b10dab7a9871c17de0accf07089ff348e
products:
  - Lightning Aura Components Developer Guide
  - Platform Developer Content
---

# Sending Messages to the Lightning Container Component

Use the methods in the lightning-container NPM module to send messages from the JavaScript code framed by `lightning:container`.

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](https://www.npmjs.com/package/lightning-container).

Add the lightning-container module as a dependency in your code to implement the messaging framework in your app.

```javascript
import LCC from 'lightning-container';
```

`lightning-container` must also be listed as a dependency in your app’s package.json file.

The code to send a message to `lightning:container` from the app is simple. This code corresponds to the code samples in [Sending Messages from the Lightning Container Component](https://developer.salesforce.com/docs/platform/aura-platform/guide/container-sending-messages.md#sending-messages-from-the-lightning-container-component) and [Handling Errors in Your Container](https://developer.salesforce.com/docs/platform/aura-platform/guide/container-handling-errors.md#handling-errors-in-your-container).

```javascript
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](https://developer.salesforce.com/docs/platform/aura-platform/guide/container-api-reference.md#lightningcontainer-npm-module-reference)

**important:** Don't send cryptographic secrets like an API key in a message. It's important to keep your API key secure.

