wangEditor
wangEditor copied to clipboard
我使用insertText,插入文本,无效果!
问题描述
我react使用editor?.insertText('Hello, World!') 无任何效果! 请输入遇到的问题... 我在useEffect钩子中editor是null
wangEditor 版本
"@wangeditor/editor": "^5.1.23", "@wangeditor/editor-for-react": "^1.0.6", 我的写法是: useEffect(() => { const handleEditorTextChange = (event: any, args: any) => { insertText(); }; ipc.on("add-text", handleEditorTextChange) // 清除监听事件 return () => { ipc.off("add-text", handleEditorTextChange); }; }, [])
const insertText = () => { console.log(editor); if (editor == null) return editor?.insertText('
Hello, World!
') } <Editor
defaultConfig={editorConfig}
value={field.value}
onCreated={setEditor}
onChange={handleEditorChange}
mode="default"
style={{ height: '500px', overflowY: 'hidden' }}
/>
是否查阅了文档 ?
是的
他官网不是有demo吗
hde
在 2024-01-09 09:17:36,moonlit @.***> 写道:
他官网不是有demo吗
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
@dxrvip 生命周期问题吧,insertText就执行一次,执行的时候editor还没有挂载