安装相关依赖
npm install react-draft-wysiwyg
npm install draft-js
npm install draftjs-to-html
npm install html-to-draftjs
import React, { useEffect, useState } from 'react'
import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css'
import { EditorState, convertToRaw, ContentState } from 'draft-js'
import { Editor } from 'react-draft-wysiwyg';
import draftToHtml from 'draftjs-to-html'
import htmlToDraft from 'html-to-draftjs'
export default function Userstati() {
const [editorState, setEditorState] = useState(EditorState.createEmpty())
const onEditorStateChange = (editorState: any) => {
setEditorState(editorState)
}
const getRichText = () => {
const htmlStr = draftToHtml(
convertToRaw(editorState.getCurrentContent())
)
console.log(htmlStr)
return htmlStr
}
useEffect(()=>{
const html =