I would like to know how to use React refs
to navigate to a specific component
function App() {
const CompetencesRef = React.useRef();
const ExperiencesRef = React.useRef();
const FormationRef = React.useRef();
const RecoRef = React.useRef();
return (
<ParallaxProvider>
<ThemeProvider theme={theme}>
<div className="App">
<div className="hero">
<HeaderApp />
<ApprochApp />
</div>
<Apropos />
<Competences parentRef={CompetencesRef} />
<Experiences parentRef={ExperiencesRef} />
<Formation parentRef={FormationRef} />
<Recom parentRef={RecoRef} />
<Contact />
<Footer />
</div >
</ThemeProvider>
</ParallaxProvider>
);
}
AppHeader
const AppHeader = () => {
return (
<div >
<Headroom>
<MenuApp />
</Headroom>
</div>
)
}
export default AppHeader
AppMenu
const MenuApp = () => {
return (
<div className="menu sticky-inner grid-container">
<div className="desktop-menu">
<div className="menu-item a-propos">
<p className='button'>Me découvrir</p>
</div>
<div className="menu-item competences">
<p className='button'>Compétences </p>
</div>
<div className="menu-item experiences">
<p className='button'>Experiences</p>
</div>
<div className="menu-item formation">
<p className='button'>Formation </p>
</div>
</div>
<p className="mobile-menu">
<MenuIcon />
</p>
<div className="github-ico">
<GitHubIcon />
</div>
<div className="linkedin-ico">
<LinkedInIcon />
</div>
<div className="contact">
<div className='contact-btn'>
<span className="contact-ico"> <MessageIcon /></span> <span style={isBrowser ? { display: 'block' } : { display: 'none' }} > contact </span>
</div>
</div>
</div>
)
}
export default MenuApp
I have understood that I should declare ref on the parent component, but I'm stuck on how to pass references to the menu app and make the link between it and components.
Actually, I would not use packages like react-scroll
I think you need forwarding-refs
in the parent
in the child component