Search⌘ K

Callback Refs

Explore how to use callback refs in React to directly access and manage DOM elements. Understand their advantages over string refs, how to implement them in parent and child components, and best practices for maintaining references within class components.

What are Callback Refs?

A more flexible alternative to string refs is the callback refs. While being more flexible, their handling is slightly more cumbersome and must be managed explicitly. By using callback refs, it is possible to pass refs to a component’s child components and access their corresponding DOM elements.

As the name might suggest, callback refs are ...