Open alittlegit opened 3 years ago
import React, { useState } from 'react'; import ReactDOM from 'react-dom'; import BraftEditor from 'braft-editor'; import 'braft-editor/dist/index.css';
const RichText = () => { const [data, setData] = useState(); const handleEditorChange = (value) => { setData(value.toHTML()); };
return (
); };
export default RichText;
ReactDOM.render( , document.getElementById('container'), );
return的内容:
BraftEditor value={BraftEditor.createEditorState(data)} onChange={handleEditorChange}
同样的问题,想要封装在自定义组件中,对外只暴露 html 的字符串,就出现这种情况了
import React, { useState } from 'react'; import ReactDOM from 'react-dom'; import BraftEditor from 'braft-editor'; import 'braft-editor/dist/index.css';
const RichText = () => { const [data, setData] = useState(); const handleEditorChange = (value) => { setData(value.toHTML()); };
return (
); };
export default RichText;
ReactDOM.render( ,
document.getElementById('container'),
);