reactjs - Typescript 导出默认值:React.FunctionComponent
问题描述
我将如何在打字稿中解决这个问题。我知道我可以给它一个名字,但这不是我要问的。我在问我怎样才能仍然使用默认值。
interface IProps {
name: string,
tag: string,
}
export default ({name, tag}: IProps) => {
..... my code
});
是的,我知道这件事。
const MyComponent: React.FunctionComponent = () => {
...
export default MyComponent;
解决方案
嗯,就像你有它,除了尾随)
语法错误
import React from "react"
interface IProps {
name: string,
tag: string,
}
export default ({name, tag}: IProps): JSX.Element => {
return <p>hello { name }, some { tag }</p>
} // <- no trailing `)`
或者 -
import React from "react"
interface IProps {
name: string,
tag: string,
}
export default ({name, tag}: IProps): JSX.Element =>
<p>hello { name }, some { tag }</p>
也就是说,命名函数要好得多,尤其是出于调试目的。
推荐阅读
- python - 为什么代码无法抓取 HTML 类中的任何内容?
- php - 删除关联数组的键不起作用
- angular - 在 Angular 5 中监听文档键事件
- java - javax.naming.NameNotFoundException:名称 [jdbc/rhwebDB] 未绑定在此上下文中。找不到 [jdbc]
- java - 登录时出现此错误:在 org.json.JSONTokener.syntaxError(JSONTokener.java:449)
- python - 无法从谷歌搜索中获取文章结果
- php - php ssh linux屏幕执行
- telnet - 当我在手机上使用命令 telnet 时它不起作用
- java - 在 Jena 自定义 PropertyFunction 中等待服务器响应
- python - 如何从网页中提取表格