<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
<script type="text/babel">
const scrollToElement = (elementId) => {
const element = document.getElementById(elementId);
// Scroll to the top of the element
element.scrollIntoView({ behavior: 'smooth', block: 'start' });
<div className='container'>
<h3>React Js Scroll to Element</h3>
<button onClick={() => scrollToElement('elementToScrollTo')}>
<button onClick={() => scrollToElement('div2')}>
<button onClick={() => scrollToElement('div3')}>
<div id="elementToScrollTo" style={{ height: '300px', backgroundColor: 'blue' }}>
{/* Content for the elementToScrollTo */}
<div id="div2" style={{ height: '300px', backgroundColor: 'red' }}>
{/* Content for the first additional div */}
<div id="div3" style={{ height: '300px', backgroundColor: 'yellow' }}>
{/* Content for the second additional div */}
<div id="div4" style={{ height: '300px', backgroundColor: 'pink' }}>
{/* Content for the second additional div */}
ReactDOM.render(<App />, document.getElementById("app"));
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24);
background-color: #4CAF50;
background-color: #45a049;