1

I am currently using JQuery in Reactjs for scrolling. I realized that it is not a good idea to mix the two together and that it can be done with just React. However, I was wondering if someone could show me how to do the following in just React?

    $("#sideOne").click(function () {
    $('html, body').animate({
        scrollTop: $("#first").offset().top
        }, 2000);
    });

    <div id="mySidenav" class="sidenav">
     <a href="#first" id="sideOne" class="pink">About</a>
     <a href="#second" id="sideTwo" class="purple">Steps</a>
     <a href="#fourth" id="sideThree" class="blue">Contact</a>
    </div>

Thank you!

Stephanie
  • 11
  • 2

2 Answers2

0

You could use one of the native JavaScript solutions explained at ReactJS how to scroll to an element

or use a third-party library for that functionality like https://github.com/ganderzz/react-scroll-to or https://github.com/fisshy/react-scroll (more may be found at https://www.google.de/search?q=scrollTo+reactjs ;)

Capricorn
  • 2,061
  • 5
  • 24
  • 31
0

You could use this cool library https://github.com/fisshy/react-scroll