WuQiao
WuQiao
> 好像可以用editor.isEmpty()来判断 这个我看到了, 但是集成在表单里面,就需要根据editor的change事件的value来做验证的嘛,这样做有没有比较合适的做法呢?
> 这样子不行, 我通过 `import { Editor, Toolbar } from '@wangeditor/editor-for-react';` 使用的Editor组件 ` getEditorHtml(edt.getHtml())} mode="default" /> ` 存在state `const [editor, setEditor] = useState(null);` 然后chenge事件里面 `console.log(editor?.isEmpty()) // undefined` 一直都是undefined
@wangfupeng1988 如果 editor 一直是 undefined ,那你是如何得到 editor.getHtml() 的? editor.getHtml是在的 onChange事件上获取的,在使用了usestate存入了editor的instance之后再获取editor就是null,使用了useref之后就正常了。可能是react环境导致,使用的是官方文档的react demo
@wangfupeng1988 https://codesandbox.io/s/boring-dawn-gdtx1b?file=/src/App.tsx 输入删除后,查看控制台的输出即可
> @WaQuio 你的例子中 html state 没有设置 > > ``` > // 编辑器内容 > const [html, setHtml] = useState('hello') > ``` > > 需要把例子中html中的state相关的代码加上 https://codesandbox.io/s/boring-dawn-gdtx1b?file=/src/App.tsx 我直接运行你们官网 react demo 结果也是一样。