Undo redo in React Block Editor component

31 Aug 20255 minutes to read

The undo/redo feature in Block Editor enables users to revert or reapply changes made to the content, offering a safety net for edits and enhancing the overall editing experience.

Keyboard shortcuts

Action Windows Mac Description
Undo Ctrl + Z ⌘ + Z Reverts the last action.
Redo Ctrl + Y ⌘ + Y Reapplies the last undone action.

Configuring Undo/Redo stack

The Block Editor stores a history of actions, allowing users to perform undo and redo operations. By default, it saves up to 30 actions. You can customize this limit using the undoRedoStack property to control the maximum number of steps that can be undone or redone.

The example below sets the undo/redo history limit to 20 actions.

// 

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { BlockEditorComponent, ContentType } from '@syncfusion/ej2-react-blockeditor';

function App() {
  const blocksData = [
  {
    id: 'block-1',
    type: 'Heading',
    props: { level: 1 },
    content: [
      {
        type: ContentType.Text,
        content: 'Undo/Redo Demo'
      }
    ]
  },
  {
    id: 'block-2',
    type: 'Paragraph',
    content: [
      {
        type: ContentType.Text,
        content: 'Try adding new blocks or modifying content below:'
      }
    ]
  },
  {
    id: 'block-3',
    type: 'Paragraph',
    content: [
      {
        type: ContentType.Text,
        content: '1. Undo stack set to maximum 40 actions\n2. Press Ctrl+Z to undo\n3. Press Ctrl+Y to redo\n4. Actions include text edits, block moves, additions, deletions'
      }
    ]
  }
];

  return (

      <BlockEditorComponent
        id="blockeditor_undo"
        blocks={blocksData}
        undoRedoStack={20}
      ></BlockEditorComponent>

  );
}

export default App;

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

//
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { BlockEditorComponent, BlockModel, ContentType } from '@syncfusion/ej2-react-blockeditor';

function App() {
  
const blocksData: BlockModel[] = [
  {
    id: 'block-1',
    type: 'Heading',
    props: { level: 1 },
    content: [
      {
        type: ContentType.Text,
        content: 'Undo/Redo Demo'
      }
    ]
  },
  {
    id: 'block-2',
    type: 'Paragraph',
    content: [
      {
        type: ContentType.Text,
        content: 'Try adding new blocks or modifying content below:'
      }
    ]
  },
  {
    id: 'block-3',
    type: 'Paragraph',
    content: [
      {
        type: ContentType.Text,
        content: '1. Undo stack set to maximum 40 actions\n2. Press Ctrl+Z to undo\n3. Press Ctrl+Y to redo\n4. Actions include text edits, block moves, additions, deletions'
      }
    ]
  }
];
  return (

      <BlockEditorComponent
        id="blockeditor_undo"
        blocks={blocksData}
        undoRedoStack={20}
      ></BlockEditorComponent>

  );
}

export default App;

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