# Mentions Actions

In this example, we will demonstrate how to utilize custom functions that run on hover and click events of a mentioned user in a message. We pass `onMentionsHover` and `onMentionsClick` functions as props to either the [`Channel`](/chat/docs/sdk/react/v11/components/core-components/channel/), [`MessageList`](/chat/docs/sdk/react/v11/components/core-components/message-list/) or [`VirtualizedMessagelist`](/chat/docs/sdk/react/v11/components/core-components/virtualized-list/) components to achieve the desired result.

Both of the event handler functions receive apropriate event object as their first argument and an array of users mentioned within targeted message as their second argument. To target specific user we will need to acess [`event.target.dataset`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset) and look for `userId`.

## Mention Click Action

In this example, we'll show how to properly target clicked user and display their name through `window.alert` dialog. Click handler can be helpful for when you need to navigate to user's profile.

```tsx
import { Channel } from "stream-chat-react";
import type { CustomMentionHandler } from "stream-chat-react";

const handleMentionsClick: CustomMentionHandler = (event, mentionedUsers) => {
  const userId = event.target.dataset.userId;
  if (!userId) return;

  const user = mentionedUsers.find((user) => user.id === userId);

  window.alert(`Mentioned user: ${user.name || user.id}`);
};

export const WrappedChannel = ({ children }) => {
  return <Channel onMentionsClick={handleMentionsClick}>{children}</Channel>;
};
```

## Mention Hover Action

For a simple hover example, we will randomly change the color of the mentioned user text. Through DOM manipulation, we can use the `target` field on the `event` to change the color.

```tsx
import { Channel } from "stream-chat-react";
import type { CustomMentionHandler } from "stream-chat-react";

const handleMentionsHover: CustomMentionHandler = (event) => {
  if (!event.target.dataset.userId) return;

  const randomColor = Math.floor(Math.random() * 16777215).toString(16);
  event.target.style.color = `#${randomColor}`;
};

export const WrappedChannel = ({ children }) => {
  return <Channel onMentionsHover={handleMentionsHover}>{children}</Channel>;
};
```

## Custom Mention Component

If you wish to access certain contexts (like [`MessageContext`](/chat/docs/sdk/react/v11/components/contexts/message-context/)) and have more control over what is being rendered and what other events you'd want to attach to specific mention elements then you'd use a custom [`Mention`](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Message/renderText/componentRenderers/Mention.tsx) component, see [_Custom Element Rendering_](/chat/docs/sdk/react/v11/components/message-components/render-text#custom-element-rendering/) for more information.


---

This page was last updated at 2026-05-22T16:32:10.959Z.

For the most recent version of this documentation, visit [https://getstream.io/chat/docs/sdk/react/v11/guides/theming/actions/mentions-actions/](https://getstream.io/chat/docs/sdk/react/v11/guides/theming/actions/mentions-actions/).