---
title: "Comment by Favourite Jome on \"A Look at React Hooks: useRef to Scroll to an Element\" | Hashnode"
description: "This is an interesting method of achieving this feature. I&#39;ve always used the id attribute to achieve this feature but I guess this way the ref wouldn&#39;t"
url: "https://hashnode.com/posts/a-look-at-react-hooks-useref-to-scroll-to-an-element/61f3e8fa52c782474274a0e2/comment/61f56aca6bb59d5767db6bd0"
---

[Discussion](https://hashnode.com/posts/a-look-at-react-hooks-useref-to-scroll-to-an-element/61f3e8fa52c782474274a0e2)

Comment [A Look at React Hooks: useRef to Scroll to an Element](https://hashnode.com/posts/a-look-at-react-hooks-useref-to-scroll-to-an-element/61f3e8fa52c782474274a0e2)

[Favourite Jome](https://hashnode.com/@Favourite)

[Jan 29, 2022](https://hashnode.com/posts/a-look-at-react-hooks-useref-to-scroll-to-an-element/61f3e8fa52c782474274a0e2/comment/61f56aca6bb59d5767db6bd0)

This is an interesting method of achieving this feature. I've always used the id attribute to achieve this feature but I guess this way the ref wouldn't get added to the URL.

Also, I noticed the gifs aren't showing.

Thanks for sharing!

[Victoria Lo](https://hashnode.com/@victoria)

[Jan 31, 2022](https://hashnode.com/posts/a-look-at-react-hooks-useref-to-scroll-to-an-element/61f3e8fa52c782474274a0e2/comment/61f56aca6bb59d5767db6bd0#reply-61f7779800273a7c1776cc48)

Hi [Favourite Jome](https://hashnode.com/@Favourite)! Oh? That's weird, the GIFs are working on my other devices when I checked. Can you try again and let me know?

For React, we use the `ref` attribute to access DOM elements, not `id` :)

[Favourite Jome](https://hashnode.com/@Favourite)

[Jan 31, 2022](https://hashnode.com/posts/a-look-at-react-hooks-useref-to-scroll-to-an-element/61f3e8fa52c782474274a0e2/comment/61f56aca6bb59d5767db6bd0#reply-61f8213666fcfc728be1ccd5)

The Gif showed on my PC, I guess it was a network issue on my phone even though I tried different browsers on my phone.

Oh yes, I do know we make use of `ref` attribute to access DOM elements, but I meant to say you could achieve the same functionality using the `id` attribute with anchor elements and some CSS, at least that's how I would have done it.

But for this method, the `id` value would get added to the browser URL address.

Here's a pen demonstrating what I meant.

[codesandbox.io/s/lucid-browser-hlbx8](https://codesandbox.io/s/lucid-browser-hlbx8?file=/src/App.js)
