Getting Started with the React Block Editor Component

29 Aug 20256 minutes to read

This section explains how to create a simple Block Editor and configure its available functionalities in the React environment.

Dependencies

The following list of dependencies is required to use the Block Editor component in your application.

|-- @syncfusion/ej2-react-blockeditor
    |-- @syncfusion/ej2-react-base
    |-- @syncfusion/ej2-base
    |-- @syncfusion/ej2-popups
    |-- @syncfusion/ej2-buttons
    |-- @syncfusion/ej2-splitbuttons
    |-- @syncfusion/ej2-navigations
    |-- @syncfusion/ej2-dropdowns
    |-- @syncfusion/ej2-inputs

Setup for Local Development

To easily set up a React application, use create-Vite-app, which provides a faster development environment, smaller bundle sizes, and optimized builds compared to traditional tools like create-react-app. For detailed steps, refer to the Vite installation instructions. Vite sets up your environment using JavaScript and optimizes your application for production.

Note: If you prefer using create-react-app, refer to this documentation for guidance.

To create a new React application with Vite, follow these steps.

npm create vite@latest my-app

To set-up a React application in TypeScript environment, run the following command.

npm create vite@latest my-app -- --template react-ts
cd my-app
npm run dev

To set-up a React application in JavaScript environment, run the following command.

npm create vite@latest my-app -- --template react
cd my-app
npm run dev

Adding Syncfusion® packages

All available Essential® JS 2 packages are published in the npmjs.com public registry.

To install the Block Editor component package, use the following command:

npm install @syncfusion/ej2-react-blockeditor --save

Add the Block Editor Component

Now, you can start adding Block Editor component in the application. For getting started, add the Block Editor component by using <BlockEditorComponent> tag directive in src/App.tsx file using following code. Now place the below Block Editor code in the src/App.tsx.

[Class-component]

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

export default class App extends React.Component<{}, {}> {
  public render() {
    return (
        // specifies the tag for render the blockeditor component
        <BlockEditorComponent id='blockeditor'></BlockEditorComponent>
    );
  }
}

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

[Functional-component]

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

function App() {
    return (
        // specifies the tag for render the blockeditor component
        <BlockEditorComponent id="blockeditor"></BlockEditorComponent>
    );
}

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

Import CSS Styles

Import the required CSS theme files for the Block Editor and its dependencies in your src/App.css file.

@import "../node_modules/@syncfusion/ej2-base/styles/fluent2.css";
@import '../node_modules/@syncfusion/ej2-inputs/styles/fluent2.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/fluent2.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/fluent2.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/fluent2.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/fluent2.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/fluent2.css';
@import "../node_modules/@syncfusion/ej2-react-blockeditor/styles/fluent2.css";

Run the application

Now, run the npm run dev command in your terminal to start the development server. This command compiles the code and opens the application in your default web browser.

npm run dev

The following example shows a basic Block Editor component.
[Class-component]

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

export default class App extends React.Component {
  render() {
    return (
        // specifies the tag for render the BlockEditor component
        <BlockEditorComponent id="block-editor"></BlockEditorComponent>
    );
  }
}

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

export default class App extends React.Component<{}, {}> {
  public render() {
    return (
        // specifies the tag for render the BlockEditor component
        <BlockEditorComponent id="block-editor"></BlockEditorComponent>
    );
  }
}

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

[Functional-component]

{ /* Import the BlockEditor.*/ }
import { BlockEditorComponent } from '@syncfusion/ej2-react-blockeditor';
import * as React from 'react';
import * as ReactDom from 'react-dom';

function App() {
    return (
        <BlockEditorComponent id="block-editor"></BlockEditorComponent>
    );
}

ReactDom.render(<App />, document.getElementById('container'));
// Import the BlockEditor.
import { BlockEditorComponent } from '@syncfusion/ej2-react-blockeditor';
import * as React from 'react';
import * as ReactDom from 'react-dom';

// To render BlockEditor.
function App() {
    
    return (
            <BlockEditorComponent id="block-editor"></BlockEditorComponent>
    );
}
export default App;
ReactDom.render(<App />,document.getElementById('container'));