onClick 触发单击错误:current.click 不是函数

我正在尝试在另一个 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>


白板的微信
浏览 339回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript