reactjs - React:组件构造函数可以有多个参数吗?
问题描述
只是好奇组件构造函数可以有多个参数吗?
从:
constructor(props) {
super(props)
}
进入:
constructor(props, parent) {
super(props)
this.parent = parent;
}
所以父组件可以this.parent
在子组件内部分配。
例如这是父组件要初始化子组件:
constructor(props) {
super(props)
this.helpers = new Child(<i_am_not_sure_here>, this);
}
解决方案
通常,在 React 中构造函数仅用于两个目的:
- 通过将对象分配给 this.state 来初始化本地状态。
- 将事件处理程序方法绑定到实例。
查看官方文档了解更多信息:
推荐阅读
- python - 如何将 bash 命令注入 inline-python?
- mysql - Aurora 无服务器:无法连接以进行复制
- java - 我正在研究 API 并在 android 中获得 JSON 的结果
- checkbox - 我隐藏数字签名,直到每个字段和复选框都完成。但是,我的代码没有将复选框识别为未选中
- python-3.x - Bitbucket 管道构建永无止境
- hive - 如果table1中有特定行,如何编写插入table2的hive sql
- python - OrdinalEncoder:将级别传递给序数变量
- c# - 如何在 C# 中使用 Nest 在弹性中删除特定文档
- database - 将图像从服务器发送到客户端的专业方式
- ios - 你如何reterosceptively 将一个IOS UITableViewCell 变成一个标题?