Events in React Chat UI

11 Aug 202620 minutes to read

This section describes the events that the Chat UI component triggers when specific actions are performed. The following events are available:

created

The Chat UI component triggers the created event after the component has been rendered. This event is useful for performing actions once the Chat UI is fully initialized and ready for interaction.

import { ChatUIComponent } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from "react-dom";

function App() {
    
    const created = () => {
        // Your required action here
    }
    const currentUserModel = {
        id: "user1",
        user: "Albert"
    };

    return (
        // specifies the tag for render the Chat UI component
        <ChatUIComponent user={currentUserModel} created={created}></ChatUIComponent>
    );
}

ReactDOM.render(<App />, document.getElementById('container'));
import { ChatUIComponent, UserModel } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from "react-dom";

function App() {
    
    const created = () => {
        // Your required action here
    }

    const currentUserModel: UserModel = {
        id: "user1",
        user: "Albert"
    };

    return (
        // specifies the tag for render the Chat UI component
        <ChatUIComponent user={currentUserModel} created={created} ></ChatUIComponent>
    );
}

ReactDOM.render(<App />, document.getElementById('container'));

messageSend

The messageSend event is triggered before a message is sent from the Chat UI component.

import { ChatUIComponent } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from "react-dom";

function App() {
    
    const messageSend = () => {
        // Your required action here
    }
    const currentUserModel = {
        id: "user1",
        user: "Albert"
    };

    return (
        // specifies the tag for render the Chat UI component
        <ChatUIComponent user={currentUserModel} messageSend={messageSend}></ChatUIComponent>
    );
}

ReactDOM.render(<App />, document.getElementById('container'));
import { ChatUIComponent, UserModel } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from "react-dom";

function App() {

    const messageSend = () => {
        // Your required action here
    }
    const currentUserModel: UserModel = {
        id: "user1",
        user: "Albert"
    };

    return (
        // specifies the tag for render the Chat UI component
        <ChatUIComponent user={currentUserModel} messageSend={messageSend}></ChatUIComponent>
    );
}

ReactDOM.render(<App />, document.getElementById('container'));

userTyping

The userTyping event is triggered as a user types a message in the Chat UI input field. This is useful for implementing features like typing indicators (“User is typing…”).

import { ChatUIComponent } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from "react-dom";

function App() {
    const userTyping = () => {
        // Your required action here
    }
    const currentUserModel = {
        id: "user1",
        user: "Albert"
    };

    return (
        // specifies the tag for render the Chat UI component
        <ChatUIComponent user={currentUserModel} userTyping={userTyping} ></ChatUIComponent>
    );
}

ReactDOM.render(<App />, document.getElementById('container'));
import { ChatUIComponent, UserModel } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from "react-dom";

function App() {
    const userTyping = () => {
        // Your required action here
    }
    const currentUserModel: UserModel = {
        id: "user1",
        user: "Albert"
    };

    return (
        // specifies the tag for render the Chat UI component
        <ChatUIComponent user={currentUserModel} userTyping={userTyping} ></ChatUIComponent>
    );
}

ReactDOM.render(<App />, document.getElementById('container'));

beforeAttachmentUpload

The beforeAttachmentUpload event is triggered before attached files begin uploading in the Chat UI.

import { ChatUIComponent } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from "react-dom";

function App() {
    const beforeAttachmentUpload = (args) => {
        // Your required action here
    };

    const currentUserModel = {
        id: "user1",
        user: "Albert"
    };

    const attachmentSettings = {
      saveUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Save',
      removeUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Remove'
    };
    return (
        // specifies the tag for render the Chat UI component
        <ChatUIComponent user={currentUserModel} enableAttachments={true} attachmentSettings= {attachmentSettings} beforeAttachmentUpload={beforeAttachmentUpload} ></ChatUIComponent>
    );
}

ReactDOM.render(<App />, document.getElementById('container'));
import { ChatUIComponent, FileAttachmentSettingsModel, UserModel } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from "react-dom";

function App() {
    const beforeAttachmentUpload = (args) => {
        // Your required action here
    };

    const currentUserModel: UserModel = {
        id: "user1",
        user: "Albert"
    };

    const attachmentSettings: FileAttachmentSettingsModel = {
      saveUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Save',
      removeUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Remove'
    };
    return (
        // specifies the tag for render the Chat UI component
        <ChatUIComponent user={currentUserModel} enableAttachments={true} attachmentSettings= {attachmentSettings} beforeAttachmentUpload={beforeAttachmentUpload} ></ChatUIComponent>
    );
}

ReactDOM.render(<App />, document.getElementById('container'));

attachmentUploadSuccess

The attachmentUploadSuccess event is triggered when an attached file is successfully uploaded in the Chat UI.

import { ChatUIComponent } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from "react-dom";

function App() {
    const attachmentUploadSuccess = (args) => {
        // Your required action here
    };

    const currentUserModel = {
        id: "user1",
        user: "Albert"
    };

    const attachmentSettings = {
      saveUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Save',
      removeUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Remove'
    };
    return (
        // specifies the tag for render the Chat UI component
        <ChatUIComponent user={currentUserModel} enableAttachments={true} attachmentSettings= {attachmentSettings} attachmentUploadSuccess={attachmentUploadSuccess} ></ChatUIComponent>
    );
}

ReactDOM.render(<App />, document.getElementById('container'));
import { ChatUIComponent, FileAttachmentSettingsModel, UserModel } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from "react-dom";

function App() {
    const attachmentUploadSuccess = (args) => {
        // Your required action here
    };

    const currentUserModel: UserModel = {
        id: "user1",
        user: "Albert"
    };

    const attachmentSettings: FileAttachmentSettingsModel = {
      saveUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Save',
      removeUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Remove'
    };
    return (
        // specifies the tag for render the Chat UI component
        <ChatUIComponent user={currentUserModel} enableAttachments={true} attachmentSettings= {attachmentSettings} attachmentUploadSuccess={attachmentUploadSuccess} ></ChatUIComponent>
    );
}

ReactDOM.render(<App />, document.getElementById('container'));

attachmentUploadFailure

The attachmentUploadFailure event is triggered when an attached file upload fails in the Chat UI.

import { ChatUIComponent } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from "react-dom";

function App() {
    const attachmentUploadFailure = (args) => {
        // Your required action here
    };

    const currentUserModel = {
        id: "user1",
        user: "Albert"
    };


    const attachmentSettings = {
      saveUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Save',
      removeUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Remove'
    };
    return (
        // specifies the tag for render the Chat UI component
        <ChatUIComponent user={currentUserModel} enableAttachments={true} attachmentSettings= {attachmentSettings} attachmentUploadFailure={attachmentUploadFailure} ></ChatUIComponent>
    );
}

ReactDOM.render(<App />, document.getElementById('container'));
import { ChatUIComponent, FileAttachmentSettingsModel, UserModel } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from "react-dom";

function App() {
    const attachmentUploadFailure = (args) => {
        // Your required action here
    };

    const currentUserModel: UserModel = {
        id: "user1",
        user: "Albert"
    };


    const attachmentSettings: FileAttachmentSettingsModel = {
      saveUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Save',
      removeUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Remove'
    };
    return (
        // specifies the tag for render the Chat UI component
        <ChatUIComponent user={currentUserModel} enableAttachments={true} attachmentSettings= {attachmentSettings} attachmentUploadFailure={attachmentUploadFailure} ></ChatUIComponent>
    );
}

ReactDOM.render(<App />, document.getElementById('container'));

attachmentRemoved

The attachmentRemoved event is triggered when an attached file is removed from the Chat UI.

import { ChatUIComponent } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from "react-dom";

function App() {
    const attachmentRemoved = (args) => {
        // Your required action here
    };

    const currentUserModel = {
        id: "user1",
        user: "Albert"
    };


    const attachmentSettings = {
      saveUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Save',
      removeUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Remove'
    };
    return (
        // specifies the tag for render the Chat UI component
        <ChatUIComponent user={currentUserModel} enableAttachments={true} attachmentSettings= {attachmentSettings} attachmentRemoved={attachmentRemoved} ></ChatUIComponent>
    );
}

ReactDOM.render(<App />, document.getElementById('container'));
import { ChatUIComponent, FileAttachmentSettingsModel, UserModel } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from "react-dom";

function App() {
    const attachmentRemoved = (args) => {
        // Your required action here
    };

    const currentUserModel: UserModel = {
        id: "user1",
        user: "Albert"
    };


    const attachmentSettings: FileAttachmentSettingsModel = {
      saveUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Save',
      removeUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Remove'
    };
    return (
        // specifies the tag for render the Chat UI component
        <ChatUIComponent user={currentUserModel} enableAttachments={true} attachmentSettings= {attachmentSettings} attachmentRemoved={attachmentRemoved} ></ChatUIComponent>
    );
}

ReactDOM.render(<App />, document.getElementById('container'));

attachmentClick

The attachmentClick event is triggered when an attached file is clicked in the Chat UI.

import { ChatUIComponent } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from "react-dom";

function App() {
    const attachmentClick = (args) => {
        // Your required action here
    };

    const currentUserModel = {
        id: "user1",
        user: "Albert"
    };

    const attachmentSettings = {
      saveUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Save',
      removeUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Remove',
      attachmentClick: (args) => attachmentClick(args)
    };
    return (
        // specifies the tag for render the Chat UI component
        <ChatUIComponent user={currentUserModel} enableAttachments={true} attachmentSettings= {attachmentSettings} ></ChatUIComponent>
    );
}

ReactDOM.render(<App />, document.getElementById('container'));
import { ChatUIComponent, UserModel, FileAttachmentSettingsModel } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from "react-dom";

function App() {
    const attachmentClick = (args) => {
        // Your required action here
    };

    const currentUserModel: UserModel = {
        id: "user1",
        user: "Albert"
    };


    const attachmentSettings: FileAttachmentSettingsModel = {
      saveUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Save',
      removeUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Remove',
      attachmentClick: (args) => attachmentClick(args)
    };
    return (
        // specifies the tag for render the Chat UI component
        <ChatUIComponent user={currentUserModel} enableAttachments={true} attachmentSettings= {attachmentSettings} ></ChatUIComponent>
    );
}

ReactDOM.render(<App />, document.getElementById('container'));