Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Get a Reference to a DOM Element in React with the useRef Hook

    Chris AchardChris Achard

    Most of the time you don't need access to the actual DOM when developing React applications. But when you do need to, there's a hook that will give you access to the DOM.

    In this lesson, we'll use the useRef hook to get a reference to a div element. Then we'll print the dimensions of that element - just to show that we have access to the actual DOM element; but you can use this element now to do anything you'd typically do with an element.

    The one trick to using the useRef hook is to remember to call .current on the reference to get the actual element.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson