Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.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 Typescript导出默认值:React.FunctionComponent_Reactjs_Typescript - Fatal编程技术网

Reactjs Typescript导出默认值:React.FunctionComponent

Reactjs Typescript导出默认值:React.FunctionComponent,reactjs,typescript,Reactjs,Typescript,我将如何在打字脚本中进行此操作。我知道我可以给它起个名字,但这不是我想要的。我在问,我怎么还能使用默认值呢 interface IProps { name: string, tag: string, } export default ({name, tag}: IProps) => { ..... my code }); 是的,我知道。 const MyComponent: React.FunctionComponent = () => { ... export de

我将如何在打字脚本中进行此操作。我知道我可以给它起个名字,但这不是我想要的。我在问,我怎么还能使用默认值呢

interface IProps {
  name: string,
  tag: string,
}

export default ({name, tag}: IProps) => {
 ..... my code 
});
是的,我知道。

const MyComponent: React.FunctionComponent = () => {
...
export default MyComponent;

嗯,和你的完全一样,除了后面的
语法错误

从“React”导入React
接口IProps{
名称:string,
标签:字符串,
}
导出默认值({name,tag}:IProps):JSX.Element=>{
returnhello{name},some{tag}

} // 你好{name},一些{tag}


也就是说,命名函数要好得多,特别是用于调试目的。

那么您不会使用React.FunctionComponent而不是JSX.Element?谢谢你的帮助:)@me-me-Yep,功能组件只是一个接受道具作为对象并返回JSX兼容内容的组件。您所需要做的就是符合这个期望。@me-me,这里有一个使用
React.FunctionComponent
。我个人不认为有什么好处,除非你试图实施一个非常具体的约束。