react中控制节点

class App extends React.Component {
  handleClick = () => {
    const { input } = this.inputRef; // 如果是textArea的话,const { textAreaRef } = this.inputRef;
    input.focus();
    input.setSelectionRange(0, input.value.length);
    // input.select(); // 可全部选中
  };
  
  render() {
    return (
      <div>
        <Input ref={(input) => { this.inputRef = input; }} defaultValue="foo" />
        <button onClick={this.handleClick}>Focus</button>
      </div>
    );
  }
}
原文地址:https://www.cnblogs.com/cazj/p/11661469.html