K
K
KnightForce2017-09-04 10:13:47
React
KnightForce, 2017-09-04 10:13:47

React. Why is ref={()=>{}} faster than ref={this.myGetRef}?

Using ref in this way takes a long time to render the component.

class A extends Component {
 constructor(props) {
    this.getRef=this.getRef.bind(this);
 }

 getRef(input) {
  this.input = input;
 }
 
 render() {
    return <TextInput ref={this.getRef}/>
 }
}

But if you write like this, then everything works quickly:
class A extends Component {
 constructor(props) {
 }
 
 render() {
    return <TextInput ref={(input)=>{this.input = input}}/>
 }
}

Why?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question