Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Scroll to an element from another component React Typescript

I have a Landing component where all my components, such as my NavBar, services etc., are grouped together. I did this to prevent my Landing component from being too big.

However, I’d like it to scroll directly to my Services component when I click on the Services link in my NavBar.

I can’t see how to do this with external components. Could someone help me? Thanks

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import React, {useEffect, useRef} from 'react';
import LandingNavBar from "./components/LandingNavBar";
import Header from "./components/Header";
import {initFlowbite} from 'flowbite'
import Services from "./components/Services";

function Landing() {
    useEffect(() => {
        initFlowbite()
    }, []);

    return (
        <div>
            <LandingNavBar/>
            <Header/>
            <Services/>
        </div>
    );
}

export default Landing;

>Solution :

Did you try to use #id with anchor tag
check examples:

  1. https://www.geeksforgeeks.org/how-to-redirect-to-a-particular-section-of-a-page-using-html-or-jquery/
  2. React change view and then scroll to element
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading