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>
);
}
}
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