我想知道如何使用 Reactrefs
导航到特定组件
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>
);
}
应用标头
const AppHeader = () => {
return (
<div >
<Headroom>
<MenuApp />
</Headroom>
</div>
)
}
export default AppHeader
应用菜单
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
我知道我应该在父组件上声明 ref ,但我一直坚持如何将引用传递给菜单应用程序并在它和组件之间建立链接。
实际上,我不会使用像react-scroll这样的包