【发布时间】:2022-12-04 06:36:19
【问题描述】:
由于加载 tinyMCE 文本编辑器需要一些时间,我使用使用效果,使用参考钩子来检测文本编辑器何时准备就绪,并且可能会更新状态以呈现编辑器而不是微调器。然而,使用效果即使在初始化之后也不会被调用(编辑器Ref.current正在监视)。 这种方法有什么问题吗?
import React, { useRef, useEffect } from "react";
import { Editor } from "@tinymce/tinymce-react";
export default function App() {
const editorRef = useRef(null);
useEffect(() => {
console.log("editor is ready")
}, [editorRef.current]);
return (
<>
<Editor
onInit={(evt, editor) => (editorRef.current = editor)}
initialValue="<p>This is the initial content of the editor.</p>"
init={{
height: 500,
menubar: false,
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table paste code help wordcount",
],
toolbar:
"undo redo | formatselect | " +
"bold italic backcolor | alignleft aligncenter " +
"alignright alignjustify | bullist numlist outdent indent | " +
"removeformat | help",
content_style:
"body { font-family:Helvetica,Arial,sans-serif; font-size:14px }",
}}
/>
</>
);
}
【问题讨论】: