React Refs
React useRef Hook
Ref
Refs provide a way to access DOM nodes or React elements created in the render method.
usecases
- Managing focus, text selection, or media playback.
- Triggering imperative animations.
- Integrating with third-party DOM libraries.
useRef
returns a mutable ref object whose .current
property is initialized to the passed argument (initialValue). The returned object will persist for the full lifetime of the component.
Example to focus a text field
1 | function TextFieldFocus() { |