加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactjs – Flow(React Native)给我的错误使用’this.state’

发布时间:2020-12-15 06:25:31 所属栏目:百科 来源:网络整理
导读:当我在我的代码中尝试使用this.state时,流量给我以下错误: object literal: This type is incompatible with undefined. Did you forget to declare type parameter State of identifier Component ?: 这是违规代码(虽然它也发生在其他地方): class Expan
当我在我的代码中尝试使用this.state时,流量给我以下错误:

object literal:
This type is incompatible with
undefined. Did you forget to declare type parameter State of identifier Component?:

这是违规代码(虽然它也发生在其他地方):

class ExpandingCell extends Component {
    constructor(props) {
    super(props);
    this.state = {
        isExpanded: false
    };
}

任何帮助将不胜感激=)

您需要在使用该属性之前定义state属性的类型。
class ComponentA extends Component {
    state: {
        isExpanded: Boolean;
    };
    constructor(props) {
        super(props);
        this.state = {
            isExpanded: false
        };
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读