javascript - 为什么我的 React ref 没有安装在 map 函数中?
问题描述
我正在使用这条线使用 ref 回调创建 refs
setRef = (ref) => {
this.inputRefs.push(ref);
};
这是我的渲染函数,其中添加了引用
render() {
return (
<div onClick={(e) => { this.removePopUpBox(e) }}>
<div> {this.state.popUpBox ? <PopUpBox /> : null} </div>
<div className="add" onClick={this.addPopUpBox}>+</div>
<div className="tasks-wrap">
{this.state.items.map((task, index) => {
return (
<Item ref={this.setRef} index={index} key={index} item={task} remove={this.remove}/>
)})}
</div>
</div>);
}
这是我的构造函数
constructor(props) {
super(props);
this.inputRefs = []
}
出于某种原因,我的 refs 已初始化但没有安装到元素上,因此对 current 的任何调用都返回为未定义。谢谢!
解决方案
推荐阅读
- node.js - 我正在使用 node.js 并且我不断收到一条错误消息:错误:连接 ETIMEOUT ,
- javascript - 在 React 中单击按钮时停止计时器
- c - 查找字符串中的空格和字母数字字符 C语言
- html - 将 Discord 小部件放置在网页上的某个位置
- ruby-on-rails - 为什么 Rails 6(以及可能的其他版本)在 RoutingErrors 方面以不同的方式对待 / 路径?
- javascript - 如何保存 Cookie 并使用 Curl 登录?
- pycharm - PyCharm 中 ReST 的校对
- log4j2 - JUnit XML system-out 显示来自所有线程的日志
- swift - CloudKit 无法删除资产文件的无法理解的错误
- ios - 如何使用宽度的框架修饰符使多列列表中的 1 列具有相同的宽度,以保持灵活性