reactjs - 在 React 中使用 TypeScript 时“this.state”从何而来
问题描述
this.state
我想知道将 React 与 TypeScript 一起使用时该属性从何而来?
public constructor(props: any) {
super(props);
this.state = {
userName:"Code to html, one way -->",
password:""
};
}
我们没有在 super() 调用中导入它,那么它是从哪里来的呢?
解决方案
它来自您通过扩展类继承的 React 组件的内部实现React.Component
:
class MyComponent from React.Component {
// this.setState, this.state,
// lifecycle methods and more
}
请参阅React.Component
及其实例属性。
推荐阅读
- actions-on-google - DialogFlow:成功链接 Google 帐户后 JSON 中缺少“用户”属性
- cjson - cJSON 字段不存在
- c++ - SDL2 加载带有特殊字符的文件
- c# - iTexsharp pdf中表格单元格的不同单元格事件
- android - 为 AndroidViewModel 创建 ViewModelFactory 的正确方法是什么
- java - JUnit 测试 - 如何检查扫描仪的各种输入不匹配
- sql - SQL Server:如何更改 sa 的密码?
- php - MVC 模式:如果模型需要调用其视图的函数,如何解决这个问题?
- amazon-s3 - spark.read.parquet 在 Colab 中不起作用
- javascript - 正则表达式:匹配所有字符串,但捕获两个符号之间的组