useRef

useRef

The useRef hook creates a reference as a variable which can be used for a number of things in a React application.

This reference is mutable, unlike stateful variables.

The most common use case is to assign DOM elements to them so you can view and modify them outside of the standard React lifecycle.

However, any value can be assigned to a ref, such as a string, an object, a number and so on.

At its core, a ref is a variable that get's persisted between renders and does not cause any renders of its own.

You can access the value by getting the current field on the ref.

Further resources

Related topics

© 2024 MWXYZ