How to get values from input types using this.refs in reactjs?

前端 未结 11 984
耶瑟儿~
耶瑟儿~ 2021-02-03 21:23

Not able to get values of input type using this.refs... how to get that values from input type

   export class BusinessDetailsForm extends Component {
      subm         


        
11条回答
  •  深忆病人
    2021-02-03 21:45

    The react docu explains it very well: https://reactjs.org/docs/refs-and-the-dom.html

    this is considered legacy:

    yourHandleMethod() {
      this.googleInput.click();
    };
    
    yourRenderCode(){
      ref={(googleInput) => { this.googleInput = googleInput }}
    };
    

    whereas, this is considered the way to go:

    constructor(props){
      this.googleInput = React.createRef();
    };
    yourHandleMethod() {
      this.googleInput.current.click();
    };
    yourRenderCode(){
      
    };
    

提交回复
热议问题