Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

jodit-react

jodit240kMIT5.2.19TypeScript support: included

Jodit is awesome and usefully wysiwyg editor with filebrowser

react, jodit, html, text, editor, wysisyg, rich editor, rich text editor, rte

readme

React Jodit WYSIWYG Editor

npm npm npm

React wrapper for Jodit

Jodit React PRO it is an extended version of Jodit React with the same API, but with a lot more features.

Installation

npm install jodit-react --save

Update editor version

npm update jodit-react

Run demo

npm install --dev
npm run demo

and open

http://localhost:4000/

Usage

1. Require and use Jodit-react component inside your application.

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

const Example = ({ placeholder }) => {
    const editor = useRef(null);
    const [content, setContent] = useState('');

    const config = useMemo(() => ({
            readonly: false, // all options from https://xdsoft.net/jodit/docs/,
            placeholder: placeholder || 'Start typings...'
        }),
        [placeholder]
    );

    return (
        <JoditEditor
            ref={editor}
            value={content}
            config={config}
            tabIndex={1} // tabIndex of textarea
            onBlur={newContent => setContent(newContent)} // preferred to use only this option to update the content for performance reasons
            onChange={newContent => {}}
        />
    );
};

Jodit plugins

You can use all Jodit features and write your own plugin for example.

import JoditEditor, { Jodit } from 'jodit-react';

/**
 * @param {Jodit} jodit
 */
function preparePaste(jodit) {
    jodit.e.on(
        'paste',
        e => {
            if (confirm('Change pasted content?')) {
                jodit.e.stopPropagation('paste');
                jodit.s.insertHTML(
                    Jodit.modules.Helpers.getDataTransfer(e)
                        .getData(Jodit.constants.TEXT_HTML)
                        .replace(/a/g, 'b')
                );
                return false;
            }
        },
        { top: true }
    );
}
Jodit.plugins.add('preparePaste', preparePaste);

//...
return <JoditEditor />;

You can see how to write plugins in the documentation or on the stand

Use with Jodit PRO

You can connect any Jodit constructor and set it as the JoditConstructor property of the component.

import React from 'react';
import JoditEditor from 'jodit-react';
import {Jodit} from 'jodit-pro';
import 'jodit-pro/es5/jodit.min.css';
// ...

function App() {
  return <JoditEditor JoditConstructor={Jodit} />;
}

License

This package is available under MIT License.

changelog

Changelog

Tags:

  • :boom: [Breaking Change]
  • :rocket: [New Feature]
  • :bug: [Bug Fix]
  • :memo: [Documentation]
  • :house: [Internal]
  • :nail_care: [Polish]

5.0.9

  • Fixed ref forwarding issue

5.0.7

4.0.1

-

1.3.19

:rocket: New Feature

  • The package now re-exports imperative Jodit, so you can write plugins and use all Jodit helpers
import JoditEditor, { Jodit } from '../../src/';

/**
 * @param {Jodit} jodit
 */
function preparePaste(jodit) {
    jodit.e.on(
        'paste',
        e => {
            if (confirm('Change pasted content?')) {
                jodit.e.stopPropagation('paste');
                jodit.s.insertHTML(
                    Jodit.modules.Helpers.getDataTransfer(e)
                        .getData(Jodit.constants.TEXT_HTML)
                        .replace(/a/g, 'b')
                );
                return false;
            }
        },
        { top: true }
    );
}
Jodit.plugins.add('preparePaste', preparePaste);

//...
return <JoditEditor />;

:house: Internal

  • Update
eslint-plugin-react-hooks    ^4.5.0  →    ^4.6.0
@babel/core                 ^7.16.0  →   ^7.19.0
@babel/eslint-parser        ^7.17.0  →   ^7.18.9
@babel/preset-env           ^7.16.0  →   ^7.19.0
@babel/preset-react         ^7.16.0  →   ^7.18.6
@types/react               ^16.14.2  →  ^18.0.18
babel-loader                 ^8.2.2  →    ^8.2.5
css-loader                   ^3.6.0  →    ^6.7.1
eslint                       ^8.9.0  →   ^8.23.0
eslint-config-prettier       ^8.4.0  →    ^8.5.0
eslint-plugin-prettier       ^4.0.0  →    ^4.2.1
eslint-plugin-react         ^7.28.0  →   ^7.31.8
husky                        ^7.0.4  →    ^8.0.1
lint-staged                 ^12.3.4  →   ^13.0.3
prettier                     ^2.5.1  →    ^2.7.1
style-loader                ^0.20.3  →    ^3.3.1
webpack                     ^4.44.2  →   ^5.74.0
webpack-cli                 ^3.3.12  →   ^4.10.0
webpack-dev-server          ^3.11.0  →   ^4.11.0

1.3.18

:bug: Bug Fix

1.2.1

:bug: Bug Fix