Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何键入属性';键';关于前置无状态组件_Reactjs_Typescript_Preact - Fatal编程技术网

Reactjs 如何键入属性';键';关于前置无状态组件

Reactjs 如何键入属性';键';关于前置无状态组件,reactjs,typescript,preact,Reactjs,Typescript,Preact,以下是无状态组件: interface Props { children: JSX.Element; title: string; isHidden: boolean; } function TabContent({ children, title, isHidden }: Props): JSX.Element { return ( <section id={title} hidden={isHidden} >

以下是无状态组件:

interface Props {
  children: JSX.Element;
  title: string;
  isHidden: boolean;
}

function TabContent({ children, title, isHidden }: Props): JSX.Element {
  return (
    <section
      id={title}
      hidden={isHidden}
    >
      {children}
    </section>
  );
}

export default TabContent;
但是Typescript抱怨类型道具上不存在
属性“key”


我已经研究了如何在React中键入一个无状态组件,如下所示。它们都需要访问
React
模块,但我使用的是Preact..

Preact与React的组件类似。因此,您可以使用
组件类型
函数组件
函数组件

import { FunctionalComponent } from 'preact';

const TabContent: FunctionalComponent<Props> = ({ children, title, isHidden }) => (
    <section
        id={title}
        hidden={isHidden}
    >
        {children}
    </section>
);
从'preact'导入{FunctionalComponent};
常量选项卡内容:FunctionalComponent=({children,title,ishiden})=>(
{儿童}
);

我想你可以在
道具中添加
key?:string | number
(或任何有意义的类型)你是否尝试过使用preact本身的
FunctionComponent
ComponentType
?类似于
const-TabContent:FunctionComponent=({children,title,isHidden})=>…
我像这样从“preact”导入{h,FunctionComponent}。它起作用了。非常感谢。那我就贴出来作为答复
import { FunctionalComponent } from 'preact';

const TabContent: FunctionalComponent<Props> = ({ children, title, isHidden }) => (
    <section
        id={title}
        hidden={isHidden}
    >
        {children}
    </section>
);