-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

React Interview Guide
By :

Refs are useful when you need to work with external systems (or non-React systems) such as built-in browser APIs. There are two built-in ref Hooks available in function components. The useRef
Hook is used to declare a ref to hold any kind of value but is mainly used for DOM nodes. useImperativeHandle
is used to expose the customized ref with only the required methods.
Please note that an introduction to refs has already been covered in Chapter 2. In this section, we will go beyond what we have already discussed about refs in Chapter 2.
The useRef
Hook accepts the initial value (or default value) as an argument, like the useState
Hook. The declaration of this Hook should be placed at the top of the enclosed component.
React saves this initial value at the first render and ignores it for the next renders, but if you create an expensive object for the initial value of the ref, it might be called...