How to use React.createRef() In ReactJS
It was introduced in React 16.3. We can create a ref variable using React.createRef() and attach it to the React element by using the ref attribute of the element.
Syntax:
const func = React.createRef();
What is significance of refs in ReactJS ?
Refs are a function provided by React to access the DOM element and the React element that you might have created on your own. They are used in cases where we want to change the value of a child component, without making use of props and all. They also provide us with good functionality as we can use callbacks with them. We can create a Ref by the following three methods:
Table of Content
- Using React.createRef()
- Using useRef() hook
- Using callback ref
- Significance of Refs in React JS: