每当我尝试在代码中使用 this.state
时,Flow 都会出现以下错误:
object literal: This type is incompatible with undefined. Did you forget to declare type parameter
State
of identifierComponent
?:
这是有问题的代码(尽管它也发生在其他地方):
class ExpandingCell extends Component {
constructor(props) {
super(props);
this.state = {
isExpanded: false
};
}
任何帮助将不胜感激 =)
最佳答案
您需要为状态属性定义一个类型才能使用它。
class ComponentA extends Component {
state: {
isExpanded: Boolean
};
constructor(props) {
super(props);
this.state = {
isExpanded: false
};
}
}
关于reactjs - Flow (React Native) 使用 'this.state' 时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36860349/