Reactjs 我应该使用什么类型来匹配返回div的FunctionComponent? import React,{FunctionComponent}来自“React” 从“样式化组件”导入样式化 界面小道具{ id:字符串 } const Child=函数(props:ChildProps){ 返回 } 接口父道具{ node:FunctionComponent//如何改进此类型以匹配返回div的函数组件? } const Parent=函数(props:ParentProps){ const Node=props.Node 返回 }
你不能Reactjs 我应该使用什么类型来匹配返回div的FunctionComponent? import React,{FunctionComponent}来自“React” 从“样式化组件”导入样式化 界面小道具{ id:字符串 } const Child=函数(props:ChildProps){ 返回 } 接口父道具{ node:FunctionComponent//如何改进此类型以匹配返回div的函数组件? } const Parent=函数(props:ParentProps){ const Node=props.Node 返回 },reactjs,typescript,Reactjs,Typescript,你不能 React.FunctionComponent的类型为: interface FunctionComponent<P = {}> { (props: PropsWithChildren<P>, context?: any): ReactElement | null; propTypes?: WeakValidationMap<P>; contextTypes?: ValidationMap<any>; def
React.FunctionComponent
的类型为:
interface FunctionComponent<P = {}> {
(props: PropsWithChildren<P>, context?: any): ReactElement | null;
propTypes?: WeakValidationMap<P>;
contextTypes?: ValidationMap<any>;
defaultProps?: Partial<P>;
displayName?: string;
}
接口函数组件{
(props:PropsWithChildren
,context?:any):ReactElement | null;
propTypes?:WeakValidationMap
;
contextTypes?:ValidationMap;
defaultProps?:部分
;
displayName?:字符串;
}
它们的关键点是:
(props: PropsWithChildren<P>, context?: any): ReactElement | null;
(props:PropsWithChildren,context?:any):ReactElement | null;
因此,ReactElement
是功能组件的返回类型。所有的ReactElement
意味着它被呈现为JSXfoo
是一个ReactElement
,而我也是一个div
组件呈现的JSX不是其静态类型的一部分