Integrating Jodit Editor with React: Enhance Your Text Editing Experience!

Semih Celik
2 min readSep 7, 2024

--

Having a powerful text editor is crucial for any web application. User-friendly rich text editors can elevate your project’s user experience. In this article, we’ll guide you through how to easily integrate the popular Jodit Editor into your React application.

Let’s dive into the code and see how we can get Jodit Editor up and running in our project!

Before we jump into the code, let’s install the necessary packages. Run the following command to add the Jodit editor to your React project:

npm install jodit-react

Starting theCode:

import React, { useRef, useState } from "react";
import JoditEditor from "jodit-react";

export default function JoditEditorComponent() {
const [content, setContent] = useState("");

const editorRef = useRef(null);
const config = {
readonly: false,
toolbarAdaptive: false,
toolbarSticky: false,
table: {
enable: true,
cellResize: true,
},
};

return (
<div className="h-screen w-full">
<JoditEditor
ref={editorRef}
value={content}
config={config}
onBlur={(newContent) => setContent(newContent)}
/>
</div>
);
}
  • Using useRef: With useRef, we reference the Jodit editor instance, which allows us to control the editor when necessary. This can be helpful for manipulating or resetting the editor's content.
  • Managing Content with useState: We use the useState hook to track the content typed in the editor, ensuring the text is saved and updated as the user makes changes.
  • Config Settings: The config object enables us to customize Jodit’s toolbar, table features, and sticky toolbar functionality, giving flexibility over the editor's behavior.

That’s all! Integrating Jodit Editor into your project is as simple as that. For more advanced features and configuration options, feel free to check out Jodit’s official documentation. Thank you, and happy coding!

--

--