【发布时间】:2020-07-30 05:41:22
【问题描述】:
试图将逻辑与设计分开。
以下是我要解决的问题的简化版本。
import React, { ReactNode } from "react"
interface ChildProps {
id: string
}
const Child = function (props: ChildProps) {
return <div id={props.id} />
}
interface ParentProps {
id: string
node: ReactNode
}
const Parent = function (props: ParentProps) {
return <props.node id={props.id} /> // Throws "JSX element type 'props.node' does not have any construct or call signatures.ts(2604)" error
}
【问题讨论】:
-
你希望如何传递
node?是传入像node={MyComponent}这样的功能组件还是像node={<div>foo</div>}这样渲染 JSX? -
@AlexWayne
node={MyComponent}忘了提到我需要能够在功能块内设置该节点的道具。
标签: reactjs typescript