Props

August 27, 2025 · View on GitHub

中文文档见此

Props list

PropertyDescriptionTypedefaultNotes
idElement IDStringundefinedIf not empty, the id attributes of editor, text area and preview area are {id}, {id}_md, {id}_html
valueMarkdown contentString''
namethe name prop of textareaString'textarea'
renderHTMLRender markdown text to HTML. You can return either string, function or Promise`(text: string) => stringReactElementPromise
placeholderDefault hintStringundefined
readOnlyIs readonlyBooleanfalse
pluginsPlugin listArray<string | [EditorPlugin, any]>undefined
shortcutsEnable markdown shortcutsbooleanfalse
viewControls which items will be displayd by default, includes: menu(Menu bar), md(Editor), html(Preview)Object{ menu: true, md: true, html: true }
canViewControls which items can be displayd, includes: menu(Menu bar), md(Editor), html(Preview), fullScreen(Full screen),hideMenu(Hide button to toggle menu bar)Object{ menu: true, md: true, html: true, fullScreen: true, hideMenu: true }
htmlClassclassName of preview pane. If you require default html, please do not remove custom-html-style, like your-style custom-html-styleString'custom-html-style'
markdownClassclassName of editor panelString''
imageUrldefault image urlString''
linkUrldefault link urlString''
loggerMaxSizemax history logger sizenumber100
loggerIntervalhistory logger interval (ms)number600
tableMax amount of rows and columns that a table created through the toolbar can haveObject{ maxRow: 4, maxCol: 6 }
syncScrollModeScroll sync mode between editor and previewArray['rightFollowLeft', 'leftFollowRight']
imageAcceptAccepted file extensions for images, list of comma separated values i.e .jpg,.pngString''
onChangeCallback called on editor changeFunction({html, text}, event) => {}
onChangeTriggerConfigure when the onChange will be triggered, allow: both, beforeRender (before render html), afterRender (after render html)Enum'both
onImageUploadCalled on image upload, return a Promise that resolved with image url(file: File) => Promise<string>;undefined
onCustomImageUploadcustom image upload here, needs return Promise() => PromiseSee detail in src/editor/index.jsx

plugins

You can add plugins or define the order of plugins using plugins:

import Editor from 'react-markdown-editor-lite';
import MyPlugin from './my-plugin';

// Note: Assume MyPlugin.pluginName is 'my-plugin'

// Method 1
<Editor plugins={['header', [MyPlugin, { /* plugin config */ }]]} />

// or
Editor.use(MyPlugin, { /* plugin config */ });
<Editor
  plugins={['header', 'my-plugin']}
  pluginConfig={{
    'my-plugin': { /* plugin config */ }
  }}
/>

renderHTML

renderHTML support both HTML or ReactElement, for example, markdown-it returns HTML and react-markdown returns ReactElement. Please note: what the onChange callback gets is the properties of the current state. If renderHTML is performed asynchronously, text and html may not correspond exactly.

import React from 'react';
import MdEditor from 'react-markdown-editor-lite';
// Import styles
import 'react-markdown-editor-lite/lib/index.css';
// Two different markdown parser
import MarkdownIt from 'markdown-it';
import * as ReactMarkdown from 'react-markdown';

const mdParser = new MarkdownIt(/* Markdown-it options */);

function renderHTML(text: string) {
  // Using markdown-it
  return mdParser.render(text);
  // Using react-markdown
  return React.createElement(ReactMarkdown, {
    source: text,
  });
}

export default (props) => {
  return (<MdEditor renderHTML={renderHTML} />)
}

onImageUpload

Called on image upload

// This function can convert File object to a datauri string
function onImageUpload(file) {
  return new Promise(resolve => {
    const reader = new FileReader();
    reader.onload = data => {
      resolve(data.target.result);
    };
    reader.readAsDataURL(file);
  });
}
export default (props) => {
  return (<MdEditor onImageUpload={onImageUpload} />)
}