React with Refs
It's allow you to access DOM nodes or React elements created in the render method
When to Use Refs:
- Managing focus, text selection , or media playback
- Triggering imperative animations
- Integrating with third-party DOM libraries
Note: Don't Overuse Refs
Creating Refs:
class BlogComponent extends React.Component {
constructor(props) {
super(props);
this.blogRef = React.createRef();
}
render() {
return <div ref={this.blogRef} />;
}
}
Accessing Refs:
const node = this.blogRef.current;
Conclusion:
If you want to acess the DOM node , you can use the react refs..
Enjoy Coding.....