# 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/js/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.jsx

```jsx
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 = "https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/";
    let container = useRef(null);
    let titleBar;
    const onLoadDefault = () => {
        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 = () => {
            if (!container.current) return;
            titleBar.updateDocumentTitle();
            container.current.documentEditor.focusIn();
        };
    };
    const rendereComplete = () => {
        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) => {
        if (!container.current) return;
        if (args.item.id) {
            let value = args.item.id;
            let sampleName = 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) => {
        if (!container.current) return;
        createSpinner({
            target: document.getElementById('container')
        });
        showSpinner(document.getElementById('container'));
        let format = 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 = () => {
            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: 'By author', Value: 'byAuthor' },
        { Text: 'Blue', Value: '#0000FF' },
        { Text: 'Red', Value: '#FF0000' },
        { Text: 'Pink', Value: '#FFC0CB' },
        { Text: 'Yellow', Value: '#FFFF00' }
    ];

    const insertionDrop = useRef(null);
    const deletionDrop = useRef(null);
    const insertedRowsDrop = useRef(null);
    const deletedRowsDrop = useRef(null);
    const applyBtnRef = useRef(null);
    const [isApplyDisabled, setIsApplyDisabled] = useState(true);

    const fields = { text: 'Text', value: 'Value' };

    const onColorChange = () => {
        setIsApplyDisabled(false);
        if (applyBtnRef.current) {
            applyBtnRef.current.disabled = false;
        }
    };

    const onApply = () => {
        if (container.current)
            container.current.documentEditorSettings.revisionSettings = {
                insertRevisionColor: insertionDrop.current ? insertionDrop.current.value : undefined,
                deleteRevisionColor: deletionDrop.current ? deletionDrop.current.value : undefined,
                insertedRowColor: insertedRowsDrop.current ? insertedRowsDrop.current.value : undefined,
                deletedRowColor: deletedRowsDrop.current ? deletedRowsDrop.current.value : undefined
            }
    };
    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}
                        />
                    </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}
                        />
                    </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}
                        />
                    </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}
                        />
                    </div>
                </div>
                <div style={{ paddingTop: '15px', marginBottom: '10px' }}>
                    <ButtonComponent
                        id="apply-btn"
                        ref={applyBtnRef}
                        cssClass="e-primary"
                        disabled={isApplyDisabled}
                        onClick={onApply}
                    >
                        Apply
                    </ButtonComponent>
                </div>
            </div>
            </div>
        </div>
    );
}
export default TrackChanges;

```
