【发布时间】:2018-11-22 01:25:17
【问题描述】:
我在使用带有样式组件的refs 时遇到了困难。当我尝试在下面的类方法中访问它们时,出现以下错误:
Edit.js:42 Uncaught TypeError: this.....contains is not a function
constructor(props) {
....
this.setWrapperRef = this.setWrapperRef.bind(this);
this.handleClickOutside = this.handleClickOutside.bind(this);
}
----------
setWrapperRef = (node) => {
this.wrapperRef = node;
}
handleEdit = (e) => {
e.preventDefault();
this.props.onEdit(this.props.id, this.state.title);
}
----------
<Wrapper onSubmit={this.handleEdit} ref={this.setWrapperRef}>
...
</Wrapper>
我从this question找到了代码
我在这里做错了什么?
【问题讨论】:
-
★ 从 styled-components
v4使用ref属性可以正常工作 → Docs link
标签: javascript reactjs dom ref styled-components