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
。我个人不认为有什么好处,除非你试图实施一个非常具体的约束。