react-draft-wysiwyg - 警告:无法调用 setState
react-draft-wysiwyg - Warning: Can't call setState
我确实使用 react-draft-wysiwyg 制作了一个简单的 React 应用程序,但我收到了警告。
import React from "react";
import ReactDOM from "react-dom";
import { Editor } from "react-draft-wysiwyg";
import "../node_modules/react-draft-wysiwyg/dist/react-draft-wysiwyg.css";
ReactDOM.render(
<React.StrictMode>
<Editor />
</React.StrictMode>,
document.getElementById("root")
);
当我在控制台中单击编辑器时出现此错误,但仅当我 运行 在 StrictMode 中出现此错误时:
Warning: Can't call setState on a component that is not yet mounted.
This is a no-op, but it might indicate a bug in your application.
Instead, assign to this.state
directly or define a state = {};
class property with the desired state in the r component.
我确实为你做了一个codeSandbox:https://codesandbox.io/s/strange-monad-lxtuu?file=/src/index.js:0-295
尝试单击编辑器并查看控制台中的警告。
我做错了什么?
该包在 StrictMode 方面存在一些问题。
只需删除 StrictMode:
import React from "react";
import ReactDOM from "react-dom";
import { Editor } from "react-draft-wysiwyg";
import "../node_modules/react-draft-wysiwyg/dist/react-draft-wysiwyg.css";
ReactDOM.render(
<Editor />,
document.getElementById("root")
);
我确实使用 react-draft-wysiwyg 制作了一个简单的 React 应用程序,但我收到了警告。
import React from "react";
import ReactDOM from "react-dom";
import { Editor } from "react-draft-wysiwyg";
import "../node_modules/react-draft-wysiwyg/dist/react-draft-wysiwyg.css";
ReactDOM.render(
<React.StrictMode>
<Editor />
</React.StrictMode>,
document.getElementById("root")
);
当我在控制台中单击编辑器时出现此错误,但仅当我 运行 在 StrictMode 中出现此错误时:
Warning: Can't call setState on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to
this.state
directly or define astate = {};
class property with the desired state in the r component.
我确实为你做了一个codeSandbox:https://codesandbox.io/s/strange-monad-lxtuu?file=/src/index.js:0-295 尝试单击编辑器并查看控制台中的警告。 我做错了什么?
该包在 StrictMode 方面存在一些问题。 只需删除 StrictMode:
import React from "react";
import ReactDOM from "react-dom";
import { Editor } from "react-draft-wysiwyg";
import "../node_modules/react-draft-wysiwyg/dist/react-draft-wysiwyg.css";
ReactDOM.render(
<Editor />,
document.getElementById("root")
);