useRef

The React hook that creates a ref object, { current: initialValue }, which stays the same object for the life of the component.

In more detail

Changing ref.current does not trigger a render, which makes it right for values that do not affect the display, such as a click counter used only in handlers or an interval ID. createRef makes a ref outside components, for example in a class or a test.

Example

const inputRef = useRef<HTMLInputElement>(null);

Related terms

Taught in

References