我在我的应用程序中转换为样式化组件的组件上有一个 ref。ref 用于访问组件原始 html 元素上的 offsetHeight 和 scrollHeight 属性。一旦我将此组件切换为样式化组件,ref 现在指向样式化组件而不是原始 html 元素,我不确定如何引用基本元素。这可以做到吗?
例子:
const TextArea = styled.textarea`
display: block;
margin: 0 0 0 18%;
padding: 4px 6px;
width: 64%;
font-size: 1rem;
color: #111;`;
export default class Input extends Component {
componentDidMount() {
const height = this.textInput.scrollHeight;
// do something....
}
render() {
return (
<div>
<TextArea
ref={(input) => this.textInput = input}
></TextArea>
</div>
);
}
}