> ## Documentation Index
> Fetch the complete documentation index at: https://docs.daily.co/llms.txt
> Use this file to discover all available pages before exploring further.

# useAppMessage

> Convenience hook for the daily-js sendAppMessage() method.

`useAppMessage({ onAppMessage?: Function}) : Object`

`useAppMessage` can also set up an optional callback for the [`app-message`](https://docs.daily.co/reference/daily-js/events/messaging-events#app-message) event.

## Parameters

**onAppMessage** `Function`

Callback for the [`app-message`](https://docs.daily.co/reference/daily-js/events/messaging-events#app-message) event. When an [`app-message`](https://docs.daily.co/reference/daily-js/events/messaging-events#app-message) is sent, the callback will be called with two arguments:

* `ev` (`Object`): The original [event payload](https://docs.daily.co/reference/daily-js/events/messaging-events.md#app-message) sent from `daily-js`.
* `sendAppMessage` (`Function`): The function reference that was created internally inside `useAppMessage`. This avoids having to call the hook twice in order to respond to an `app-message` with an `app-message`.

## Return value

**sendAppMessage** `Function`

Wraps [sendAppMessage()](https://docs.daily.co/reference/daily-js/instance-methods/send-app-message.md).

## Example

```jsx theme={null}
import { useAppMessage } from '@daily-co/daily-react';
import { useCallback, useState } from 'react';

export const AppMessageDemo = () => {
  const [messages, setMessages] = useState([]);

  const sendAppMessage = useAppMessage({
    onAppMessage: useCallback((ev) => setMessages((m) => [...m, ev]), []),
  });

  useEffect(() => {
    sendAppMessage({ msg: 'Hi, everyone' }, '*');
  }, [sendAppMessage]);

  return (
    <ul>
      {messages.map((ev) => (
        <li>
          {ev.fromId}: {JSON.stringify(ev.data)}
        </li>
      ))}
    </ul>
  );
};
```

## See also

> [card] daily-js methods
>
> * [sendAppMessage()](https://docs.daily.co/reference/daily-js/instance-methods/send-app-message.md)

> [card] Events
>
> * [app-message](https://docs.daily.co/reference/daily-js/events/messaging-events.md#app-message)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.