我正在尝试在另一个 onClick 事件函数上触发单击按钮。
错误:未捕获的类型错误:this.clickBack.current.click 不是函数
React 版本是 16.8.6
constructor(props) {
super(props)
this.clickBack = React.createRef();
this.startInterview = this.startInterview.bind(this);
}
startInterview(){
console.log('hello') // output : hello
console.log(this.clickBack.current); // output : Button {props: {…}, context: {…}, refs: {…}, updater: {…}, onClick: ƒ, …}
this.clickBack.current.click(); // output : Uncaught TypeError: this.clickBack.current.click is not a function
}
在渲染 -> 返回方法中
<Link to={backLink}>
<Button ref={this.clickBack}> Back</Button>
</Link>
<Button onClick={this.startInterview}> Start Interview</Button>
相关分类