我正在尝试在 Tiny mce 上使用 React 版本。我是 react 初学者。
当我在我的组件中添加组件时,我在编译时收到此错误:
'Editor' cannot be used as a JSX component.
Its instance type 'Editor' is not a valid JSX element.
The types returned by 'render()' are incompatible between these types.
Type 'ReactElement<{ ref: RefObject<HTMLElement>; id: string; }, string | JSXElementConstructor<any>>' is not assignable to type 'ReactNode'.
Property 'children' is missing in type 'ReactElement<{ ref: RefObject<HTMLElement>; id: string; }, string | JSXElementConstructor<any>>' but required in type 'ReactPortal'.
我的代码:
import React from "react";
import { Editor } from "@tinymce/tinymce-react";
const Dummy = () => <Editor apiKey={"hgt9dr50djqpx23dm6h18u9dsayv95elris5dxsqlrc0ht37"}
init={{...}}
onEditorChange={()=>null}/>
export default Dummy;
谢谢:)
最佳答案
这几天我也遇到了类似的问题。它似乎与 typescript 更新有关。
作为解决方法,请在错误行正上方的行中添加以下内容。
{/* @ts-ignore*/}
<Editor ....
告诉 typescript 检查器忽略以下代码行。
由于 React 需要括号,但该行只是 JS 注释,但 typescript 会读取它。
关于reactjs - Tinymce React组件 'Editor'不能用作JSX组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71843690/