For Functional components;
import React, {useRef} from 'react';
function ScrollingExample (props) {
// create our ref
const refToTop = useRef();
return (
<h1 ref={refToTop}> I wanna be seen </h1>
// then add enough contents to show scroll on page
<a onClick={()=>{
setTimeout(() => { refToTop.current.scrollIntoView({ behavior: 'smooth' })}, 500)
}}> Take me to the element <a>
);
}