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.
Love this playlist. Would love to see more videos like this :) Please keep up the good work!
Thanks @Koneykoya! I actually do have a couple more hooks videos planned :) Plus more playlists to come!