javascript - 在构造函数中设置状态时出现错误
问题描述
我正在尝试在我的反应代码中使用 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
我无法找到解决方案,也尝试了此方法但不起作用。请问有人可以帮忙吗?
解决方案
推荐阅读
- r - 检查 R 中按两列分组的变量的重叠
- protractor - 有没有办法在动态数据(不断变化)上运行 BDD(自动化测试),而且以前的数据每 2 周都会被清除一次?
- java - 了解 Java 9+ 上的部署
- c# - 如何创建类类型对象的数组?
- php - 将不同结构的数组合并为一个,无需重新排列键或值
- html - 我们如何让 pandoc 从 markdown 生成漂亮的、人类可读的 HTML?
- symfony - Symmfony & Sonata:如何从 AbstractAdmin 扩展访问 EntityManagerInterface?
- json - Firebase 在创建用户后使用自定义字段更新用户数据
- r - 找到条件 = T 时,我需要 R 开始过滤行
- c# - 在 C# 中使用 Deedle 进行成对匹配和窗口化