反应无状态组件中可编辑的内容 [英] React contenteditable in stateless component

查看:68
本文介绍了反应无状态组件中可编辑的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在无状态的React组件中实现一个contenteditable div。

I am trying to implement a contenteditable div inside a stateless react component.

我一直收到以下警告:

warning.js:36 Warning: A component is `contentEditable` and contains `children` managed by React. It is now your responsibility to guarantee that none of those nodes are unexpectedly modified or duplicated. This is probably not intentional.

我该如何解决?

推荐答案


与任何React应用程序一样,浏览器还应如何读取div的内容?修改
DOM的插件和扩展程序可能会导致草稿编辑器中断。

As with any React application, browser plugins and extensions that modify the DOM can cause Draft editors to break.

语法检查器可能会修改
contentEditable元素内的DOM ,添加下划线和
背景等样式。由于如果浏览器的
与预期不符,React无法协调DOM,因此编辑器状态可能无法与DOM保持
同步。

Grammar checkers, for instance, may modify the DOM within contentEditable elements, adding styles like underlines and backgrounds. Since React cannot reconcile the DOM if the browser does not match its expectations, the editor state may fail to remain in sync with the DOM.

https://github.com/facebook/draft -js / issues / 53

已知错误。至于读取div中的内容,则为该元素分配一个ID,然后为其分配一个ID。

A known error. As for reading whats in a div, assign the element an id and..

oDoc = document.getElementById("divelement");
sDefTxt = oDoc.innerHTML;

这篇关于反应无状态组件中可编辑的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆