---
title: "Discussion on \"A Look at React Hooks: useRef to Scroll to an Element\" | Hashnode"
description: "Discussion on \"A Look at React Hooks: useRef to Scroll to an Element\". Let's learn a useful application of the useRef Hook! Scrolling to a page element in React has become so much easier with this Hook"
url: "https://hashnode.com/posts/a-look-at-react-hooks-useref-to-scroll-to-an-element/61f3e8fa52c782474274a0e2"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [A Look at React Hooks: useRef to Scroll to an Element](https://blog.lo-victoria.com/a-look-at-react-hooks-useref-to-scroll-to-an-element?utm_source=hashnode&utm_medium=feed)

Let's learn a useful application of the useRef Hook! Scrolling to a page element in React has become so much easier with this Hook

Jan 28, 2022 · 6 min read · blog.lo-victoria.com  
Updated Feb 5, 2022  
Read the article

-   [#reactjs](https://hashnode.com/tag/reactjs)
-   [#reacthooks](https://hashnode.com/tag/reacthooks)
-   [#frontend-development](https://hashnode.com/tag/frontend-development)
-   [#beginners](https://hashnode.com/tag/beginners)
-   [#web-development](https://hashnode.com/tag/web-development)

## Written by

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

@victoria · Singapore

  
[View profile](https://hashnode.com/@victoria)

A nerd in books, tea, games and software.

I'm a solutions engineer lead, GitHub Star, Director of WomenDevsSG, and co founder of ragTech. I work at the intersection of tech, systems, and leadership, and this blog is where I share my journey through all three. Expect honest reflections, real experiences, and thoughts that are still forming rather than polished career advice.

## Responses 3

Markdown supported · ⌘↵ to post

[valentina](https://hashnode.com/@vpaniza)

[Jun 16, 2022](https://hashnode.com/posts/a-look-at-react-hooks-useref-to-scroll-to-an-element/61f3e8fa52c782474274a0e2/comment/62ab09a11a89c91850b1a6df)

Hi Victoria! Great article

I have one question though. I have let's say a home page, which has multiple sections, each section with its own reference. I am able to, by clicking a button, scrolling to a section (I'm not using <Link> nor <Router>). But, what I'm trying to do now is, inside that section, click a new button, that scrolls to another section (which is not a child) of the home page.

Do you think it is possible without using the router component?

Thank you very much! Your articles are really helpful

[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)

[Andrew Baisden](https://hashnode.com/@andrewbaisden)

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

Great article [Victoria Lo](https://hashnode.com/@victoria) probably going to be using this type of functionality in a project soon.

[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/61f53d214bea13573e62d780#reply-61f7774800273a7c1776cc38)

Thanks [Andrew Baisden](https://hashnode.com/@andrewbaisden)! I hope to see your awesome project soon~

[Andrew Baisden](https://hashnode.com/@andrewbaisden)

[Feb 19, 2022](https://hashnode.com/posts/a-look-at-react-hooks-useref-to-scroll-to-an-element/61f3e8fa52c782474274a0e2/comment/61f53d214bea13573e62d780#reply-6210df50c6ed3906e81c2331)

That project was my new portfolio website which is now complete [Victoria Lo](https://hashnode.com/@victoria) .

[andrewbaisden.com](https://andrewbaisden.com/)

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

[Feb 19, 2022](https://hashnode.com/posts/a-look-at-react-hooks-useref-to-scroll-to-an-element/61f3e8fa52c782474274a0e2/comment/61f53d214bea13573e62d780#reply-6210f53030c8050670ed2f61)

[Andrew Baisden](https://hashnode.com/@andrewbaisden) WOW! Your website looks amazing! Well done! 👏👏
