首页 > 解决方案 > 在构造函数中设置状态时出现错误

问题描述

我正在尝试在我的反应代码中使用 Flow,但我无法解决这个 1 错误。这是我的代码

type State = {
  showClearSearchButton: Boolean,
  location: String
};

class XYZ extends Component<State> {
  constructor (props: any) {
    super(props);
    this.state = {
      showClearSearchButton: false, (this line throws error)
      location: '' (this line throws error)
    };
  }
}

以上2行抛出错误Flow: object-literal. This type is incompatible with undefined

我无法找到解决方案,也尝试了此方法但不起作用。请问有人可以帮忙吗?

标签: javascriptreactjsreact-nativeflowtype

解决方案


推荐阅读