Skip to main content
Version: v11

System Message

A system message is a message generated by a system event, such as banning or muting a user. These are sent from the backend and displayed via the VirtualizedMessageList and MessageList components automatically. In this guide, we will demonstrate how to create and override the default component.

Default System Message Component

For reference, the default system message component, EventComponent (image below) displays all pertinent information about the event that occurred. The two list components display these messages only if message is of type system (message.type === "system").

Default System Message

Custom System Message Component

Our custom component will display the message text, date, and the actor (user who triggered the event) with added styling. For this complete override of the default component, we will utilize the MessageSystem prop on Channel through which it's being passed to ComponentContext which allows you to hook into the component override mechanism used throughout the SDK.

note

To see your custom component in action, try muting a user by using the / command. For example, type /mute followed by a user mention, @. These commands must be enabled in the Dashboard.

import { Avatar as DefaultAvatar, Channel } from 'stream-chat-react';
import type { EventComponentProps } from 'stream-chat-react';

const CustomSystemMessage = (props: EventComponentProps) => {
const { Avatar = DefaultAvatar, message } = props;

const { created_at = '', text, user } = message;
const date = created_at.toString();

return (
<div className='custom-system-message'>
<div>
Event: <strong>{text?.trim()}</strong> at {date}
</div>
<div className='custom-system-message__actor'>
Actor:
<Avatar image={user?.image} shape='square' size={20} />
{user?.name}
</div>
</div>
);
};

//...

<Channel MessageSystem={CustomSystemMessage}>...</Channel>;

Custom System Message

Did you find this page helpful?