Simulate click event on react element

后端 未结 7 1978
孤独总比滥情好
孤独总比滥情好 2020-12-03 03:06

I\'m trying to simulate a .click() event on a React element but I can\'t figure out why it is not working (It\'s not reacting when I\'m firing the

7条回答
  •  猫巷女王i
    2020-12-03 03:38

    Use refs to get the element in the callback function and trigger a click using click() function.

    class Example extends React.Component{
      simulateClick(e) {
        e.click()
      }
      render(){
        return 
    console.log('clicked')}> hello
    } } ReactDOM.render(, document.getElementById('app'))
    
    
    

提交回复
热议问题