If you want to manually trigger click event in ReactJS? You could use the ref prop to acquire a reference to the underlying HTMLInputElement object through a callback, store the reference as a class property, then use that reference to later trigger a click from your event handlers using the HTMLElement.click method.
1 2 3 4 5 6 7 8 9 10 11 12 13 | class MyComponent extends React.Component { render() { return ( <div onClick={this.handleClick}> <input ref={input => this.inputElement = input} /> </div> ); } handleClick = (e) => { this.inputElement.click(); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.