import BraftEditor from 'braft-editor'; import 'braft-editor/dist/index.css'; import React, { useEffect, useState } from 'react'; const { createEditorState } = BraftEditor; const RichTextEditor = ({ name, onChange, value, ...rest }) => { const [editor, set] = useState(null); useEffect(() => { if (value !== undefined) { set(createEditorState(value)); } }, [value]); const handleChange = editor => { set(editor); // const htmlContent = editor.toHTML(); // onChange(name, htmlContent); }; const onSave = () => { // Pressing ctrl + s when the editor has focus will execute this method // Before the editor content is submitted to the server, you can directly call editorState.toHTML () to get the HTML content const htmlContent = editor.toHTML(); if (name) { onChange(name, htmlContent); } else { onChange(htmlContent); } }; return (
); }; export default RichTextEditor;