首页 > 解决方案 > React 和 Slate 的 TypeScript 错误:“IntrinsicAttributes”类型上不存在属性“renderElement”

问题描述

我正在尝试通过以下教程学习如何使用 Slate: Defining Custom Elements

我已经(按照教程进行了轻微的风格更改)添加了以下代码:

export default function App() {
  const renderElement = useCallback((props) => {
    switch (props.element.type) {
      case "code":
        return <Code {...props} />
      default:
        return <Default {...props} />
    }
  }, [])

  return <Editor renderElement={renderElement} />
}

问题是我收到以下 TypeScript 错误:

Type '{ renderElement: (props: any) => Element; }' is not assignable to type 'IntrinsicAttributes'.
  Property 'renderElement' does not exist on type 'IntrinsicAttributes'. ts(2322)

知道为什么我会收到此错误以及如何解决它吗?

标签: javascriptreactjstypescriptslate.js

解决方案


我不熟悉有问题的库,但从您链接的文档看来,renderElement道具在<Editable />组件上而不是<Editor />. 这可能是问题吗?


推荐阅读