Getting Started with React Block Editor Component
7 Jul 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: To create a React application using
create-react-app
, refer to this documentation for more details.
To create a new React application, run the following command.
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 the available Essential® JS 2 packages are published in npmjs.com
public registry.
To install Block Editor component, use the following command
npm install @syncfusion/ej2-react-blockeditor --save
Adding 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'));
Adding CSS Reference
Import the Block Editor component required CSS references as follows in src/App.css
.
@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 the console to start the development server. This command compiles your code and serves the application locally, opening it in the 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'));