wangEditor icon indicating copy to clipboard operation
wangEditor copied to clipboard

我使用insertText,插入文本,无效果!

Open dxrvip opened this issue 1 year ago • 3 comments
trafficstars

问题描述

我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' }}
            />

是否查阅了文档 ?

是的

dxrvip avatar Dec 30 '23 17:12 dxrvip

他官网不是有demo吗

moonlitusun avatar Jan 09 '24 01:01 moonlitusun

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 avatar Jan 09 '24 15:01 dxrvip

@dxrvip 生命周期问题吧,insertText就执行一次,执行的时候editor还没有挂载

cycleccc avatar Mar 11 '24 10:03 cycleccc