【发布时间】:2017-05-24 10:32:24
【问题描述】:
我想知道用打字稿定义反应类组件的推荐方法是否使用 void 作为状态类型:
class MyComponent extends React.Component<any, void> {
constructor(props) {
super(props);
// The typescript compiler won't allow this using void type
// this.state = {...}
[...]
}
您知道推荐的或更好的方法吗?
注意:组件必须是一个类,因为我需要生命周期方法
【问题讨论】:
-
这样定义组件有什么问题?
-
没关系,但我正在寻找某种官方方式
标签: reactjs typescript