React useRef Hook

Photo by Brianna Santellan on Unsplash

In this post we’ll cover what the useRef Hook is, what we can use it for and some advice for using it.

The useRef Hook is a function that returns a mutable ref object whose .current property is initialized with the passed argument (initialValue). The returned object will persist for the full lifetime of the component.

const refContainer = useRef(initialValue);