在下面的单页案例中,如何在组件之间切换?理想情况下,当您单击时menu-item
,相关组件将显示,而其他组件将隐藏。
反应
import React, { useState } from 'react';
import About from "./components/About";
import Projects from "./components/Projects";
import Contact from "./components/Contact";
const App = () => {
// Toggle state(s) here?
// Toggle function(s) here?
return (
<div className="nav">
<ul className="menu">
<li className="menu-item">About</li>
<li className="menu-item">Projects</li>
<li className="menu-item">Contact</li>
</ul>
</div>
<div className="container">
<About />
<Projects />
<Contact />
</div>
)
};
export default App;