Sunday, 20 August 2017

What is ref in ReactJs ?

It is one of the attribute of React Element.
It provides simple access to the DOM Element represented by a React Element.
Attribute keyword is "ref" when use as an attribute but at the time of access element use as a "refs".

e.g.

class User extends Component {
    constructor(p){
        super(p)
    }

    onUserSelect(){
        console.log(this.refs.user.value);
    }

    render() {
        return (
<div>
              <label>Name</label>
              <input type="text" ref="user" />
             <button type="button" onClick={this.onUserSelect.bind(this)}>Name Check</button>
          </div>
);
    }
}

No comments:

Post a Comment

What is diffing algorithm?

  React needs to use algorithms to find out how to efficiently update the UI to match the most recent tree. The diffing algorithms is genera...