gpt4 book ai didi

reactjs - 不变违规 : Argument appears to not be a ReactComponent

转载 作者:行者123 更新时间:2023-12-03 13:27:06 24 4
gpt4 key购买 nike

我需要找到组件的offsetLeft

componentDidMount(){
var tesNo =ReactDOM.findDOMNode(this.refs.dropDown.refs.input.offsetLeft)

}
<ReactAutocomplete
ref="dropDown"
/*.......*/
/>

在调试时,我得到了变量 tesNo 的值。之后我收到此错误:

考虑向树中添加错误边界以自​​定义错误处理行为。访问this site了解有关错误边界的更多信息。不变违规:参数似乎不是 ReactComponent

如何解决这个错误?

最佳答案

我自己找到了答案。

由于我使用的是 React 版本: "^16.3.2",所以我使用了 createRef() API。

class Patient extends React.Component{
constructor(props){
super(props)
this.state = {
postn:0
}
this.dropDown=React.createRef()
}
componentDidMount(){
let left = this.dropDown.current.refs.input.offsetLeft;
this.setState({postn:left})
}
<ReactAutocomplete
ref={this.dropDown}
/*.......*/
/>
}

关于reactjs - 不变违规 : Argument appears to not be a ReactComponent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54939413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com