# docx-editor-track-changes

> Word editor shows tracked changes with accept and reject controls and a revision dropdown.

**Framework:** react  **Component:** DocxEditor  **Variant:** track-changes

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/react/ts/docx-editor-track-changes.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-react-documenteditor @syncfusion/ej2-react-dropdowns @syncfusion/ej2-react-buttons @syncfusion/ej2-popups
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/docx-editor-track-changes/DocxEditor.tsx

```tsx
import { useEffect, useRef, useState } from 'react';
import { DocumentEditorContainerComponent, Ribbon, Toolbar } from '@syncfusion/ej2-react-documenteditor';
import { trackchanges } from '../datasource/docx-editor-data';
import { DropDownListComponent  } from '@syncfusion/ej2-react-dropdowns';
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { createSpinner, showSpinner, hideSpinner } from '@syncfusion/ej2-popups';
import { TitleBar } from '../title-bar';
import '../default.component.css';

DocumentEditorContainerComponent.Inject(Toolbar, Ribbon);

const TrackChanges = () => {
    useEffect(() => {
        rendereComplete();
    }, [])
    const hostUrl: string =
        "https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/";
    let container = useRef<DocumentEditorContainerComponent>(null);
    let titleBar: TitleBar;
    const onLoadDefault = (): void => {
        if (!container.current) return;
        container.current.documentEditor.open(JSON.stringify(trackchanges));
        container.current.documentEditor.documentName = "Track Changes";
        container.current.documentEditorSettings.showRuler = true;
        container.current.documentEditor.showRestrictEditingPane(false);
        titleBar.updateDocumentTitle();
        container.current.documentChange = (): void => {
            if (!container.current) return;
            titleBar.updateDocumentTitle();
            container.current.documentEditor.focusIn();
        };
    };
    const rendereComplete = (): void => {
        if (!container.current) return;
        container.current.documentEditor.pageOutline = "#E0E0E0";
        container.current.documentEditor.acceptTab = true;
        container.current.documentEditor.resize();
        const titleBarElement = document.getElementById("documenteditor_titlebar");
        if (titleBarElement) {
            titleBar = new TitleBar(
                titleBarElement,
                container.current.documentEditor,
                true
            );
        }
        onLoadDefault();
        titleBar.showButtons(false);
    };
    
        const fileMenuItemClick = (args:any): void => {
            if (!container.current) return;
            if (args.item.id) {
                let value: string = args.item.id;
                let sampleName: string = container.current.documentEditor.documentName === '' ? 'sample' : container.current.documentEditor.documentName;
                switch (value) {
                    case 'docx':
                        container.current.documentEditor.save(sampleName, 'Docx');
                        break;
                    case 'sfdt':
                        container.current.documentEditor.save(sampleName, 'Sfdt');
                        break;
                    case 'text':
                        container.current.documentEditor.save(sampleName, 'Txt');
                        break;
                    case 'dotx':
                        container.current.documentEditor.save(sampleName, 'Dotx');
                        break;
                    case 'pdf':
                        formatSaveLocal('Pdf');
                        break;
                    case 'html':
                        formatSaveLocal('Html');
                        break;
                    case 'odt':
                        formatSaveLocal('Odt');
                        break;
                    case 'md':
                        formatSaveLocal('Md');
                        break;
                    case 'rtf':
                        formatSaveLocal('Rtf');
                        break;
                    case 'wordml':
                        formatSaveLocal('Xml');
                        break;
                }
            }
        }
    
        const formatSaveLocal = (type: string): void => {
            if (!container.current) return;
            createSpinner({
                target: document.getElementById('container')!
            });
            showSpinner(document.getElementById('container')!);
            let format: string = type;
            let url = container.current.documentEditor.serviceUrl + 'Export';
            let http = new XMLHttpRequest();
            http.open('POST', url);
            http.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
            http.responseType = 'blob';

            let sfdt = {
                Content: container.current.documentEditor.serialize(),
                Filename: container.current.documentEditor.documentName,
                Format: '.' + format,
            };

            http.onload = (): void => {
                if (http.status === 200) {
                    if (!container.current) return;
                    let responseData = http.response;
                    let blobUrl = URL.createObjectURL(responseData);
                    let downloadLink = document.createElement('a');
                    downloadLink.href = blobUrl;
                    downloadLink.download = container.current.documentEditor.documentName + '.' + format.toLowerCase();
                    document.body.appendChild(downloadLink);
                    hideSpinner(document.getElementById('container')!);
                    downloadLink.click();
                    document.body.removeChild(downloadLink);
                    URL.revokeObjectURL(blobUrl);
                } else {
                    console.error('Request failed with status:', http.status);
                    hideSpinner(document.getElementById('container')!);
                }
            };

            http.send(JSON.stringify(sfdt));
        }

    // Track Changes revision color dropdown data
    const revisionColorData: { Text: string; Value: string }[] = [
        { Text: 'By author', Value: 'byAuthor' },
        { Text: 'Blue', Value: '#0000FF' },
        { Text: 'Red', Value: '#FF0000' },
        { Text: 'Pink', Value: '#FFC0CB' },
        { Text: 'Yellow', Value: '#FFFF00' }
    ];

    const insertionDrop = useRef<DropDownListComponent>(null);
    const deletionDrop = useRef<DropDownListComponent>(null);
    const insertedRowsDrop = useRef<DropDownListComponent>(null);
    const deletedRowsDrop = useRef<DropDownListComponent>(null);
    const applyBtnRef = useRef<ButtonComponent>(null);
    const [isApplyDisabled, setIsApplyDisabled] = useState<boolean>(true);

    const fields = { text: 'Text', value: 'Value' };

    const onColorChange = (): void => {
        setIsApplyDisabled(false);
        if (applyBtnRef.current) {
            applyBtnRef.current.disabled = false;
        }
    };

    const onApply = (): void => {
        if(container.current)
            container.current.documentEditorSettings.revisionSettings = {
                insertRevisionColor: insertionDrop.current?.value as string,
                deleteRevisionColor: deletionDrop.current?.value as string,
                insertedRowColor: insertedRowsDrop.current?.value as string,
                deletedRowColor: deletedRowsDrop.current?.value as string
        }
    };
    return (
        <div className="control-pane">
        <div className='row'>
            <div className="col-lg-10 control-section">
                <div id="documenteditor_titlebar" className="e-de-ctn-title"></div>
                <div id="documenteditor_container_body" style={{"display":"block", "height": "calc(100vh - 230px)"}}>
                    <DocumentEditorContainerComponent
                        id="container"
                        ref={container}
                        style={{ display: "block" }}
                        height={"100%"}
                        toolbarMode= {"Ribbon"}
                        serviceUrl={hostUrl}
                        enableToolbar={true}
                        locale="en-US"
                        fileMenuItems={['New', 'Open', {
                            text: 'Export',
                            id: 'custom_item',
                            iconCss: 'e-icons e-export',
                            items: [
                                { id: 'sfdt', text: 'Syncfusion Document Text (*.sfdt)' },
                                { id: 'docx', text: 'Word Document (*.docx)' },
                                { id: 'dotx', text: 'Word Template (*.dotx)' },
                                { id: 'text', text: 'Plain Text (*.txt)' },
                                { id: 'pdf', text: 'PDF (*.pdf)' },
                                { id: 'html', text: 'HyperText Markup Language (*.html)' },
                                { id: 'rtf', text: 'Rich Text Format (*.rtf)' },
                                { id: 'md', text: 'Markdown (*.md)' },
                                { id: 'odt', text: 'OpenDocument Text (*.odt)' }, 
                                { id: 'wordml', text: 'Word XML Document (*.xml)' }
                            ]
                        }, 'Print']}
                        fileMenuItemClick={fileMenuItemClick}
                        showPropertiesPane={false}
                        enableTrackChanges={true}
                        userColor={"#b70f34"}
                        currentUser={"Nancy Davolio"}
                    />
                </div>
            </div>
            <div className="col-lg-2 property-section">
                <div style={{ paddingTop: '20px' }}>
                    <b>Revision Color Settings</b>
                </div>
                <div style={{ marginTop: '15px' }}>
                    <div style={{ paddingTop: '10px' }}>
                        <label style={{ display: 'block', marginBottom: '5px', fontWeight: 500 }}>Insertion:</label>
                        <DropDownListComponent
                            id="insertion-color"
                            ref={insertionDrop}
                            dataSource={revisionColorData}
                            fields={fields}
                            value="byAuthor"
                            placeholder="Insertion"
                            floatLabelType="Never"
                            width="100%"
                            change={onColorChange.bind(this)}
                        />
                    </div>
                    <div style={{ paddingTop: '10px' }}>
                        <label style={{ display: 'block', marginBottom: '5px', fontWeight: 500 }}>Deletion:</label>
                        <DropDownListComponent
                            id="deletion-color"
                            ref={deletionDrop}
                            dataSource={revisionColorData}
                            fields={fields}
                            value="byAuthor"
                            placeholder="Deletion"
                            floatLabelType="Never"
                            width="100%"
                            change={onColorChange.bind(this)}
                        />
                    </div>
                    <div style={{ paddingTop: '10px' }}>
                        <label style={{ display: 'block', marginBottom: '5px', fontWeight: 500 }}>Inserted Rows:</label>
                        <DropDownListComponent
                            id="inserted-rows-color"
                            ref={insertedRowsDrop}
                            dataSource={revisionColorData}
                            fields={fields}
                            value="byAuthor"
                            placeholder="Inserted Rows"
                            floatLabelType="Never"
                            width="100%"
                            change={onColorChange.bind(this)}
                        />
                    </div>
                    <div style={{ paddingTop: '10px' }}>
                        <label style={{ display: 'block', marginBottom: '5px', fontWeight: 500 }}>Deleted Rows:</label>
                        <DropDownListComponent
                            id="deleted-rows-color"
                            ref={deletedRowsDrop}
                            dataSource={revisionColorData}
                            fields={fields}
                            value="byAuthor"
                            placeholder="Deleted Rows"
                            floatLabelType="Never"
                            width="100%"
                            change={onColorChange.bind(this)}
                        />
                    </div>
                </div>
                <div style={{ paddingTop: '15px', marginBottom: '10px' }}>
                    <ButtonComponent
                        id="apply-btn"
                        ref={applyBtnRef}
                        cssClass="e-primary"
                        disabled={isApplyDisabled}
                        onClick={onApply.bind(this)}
                    >
                        Apply
                    </ButtonComponent>
                </div>
            </div>
            </div>
        </div>
    );
}
export default TrackChanges;

```
