How to focus a input field, which is located in a child component
问题 I have a button in a parent component. I want to focus an input field, which is located in a child component, by clicking on that button. How can I do it. 回答1: You can make use of refs to achieve the result class Parent extends React.Component { handleClick = () => { this.refs.child.refs.myInput.focus(); } render() { return ( <div> <Child ref="child"/> <button onClick={this.handleClick.bind(this)}>focus</button> </div> ) } } class Child extends React.Component { render() { return ( <input