Components can contain components that contain components. Build a three-level tree.
What to build
A layout with a sidebar menu and an article, built from nested components.
Requirements
- Write the components
Sidebar(anasidewith anh2Menuand aulof threeli:Home,Lessons,Practice),Article(anarticlewith anh2Welcomeand apPick a lesson to start.) andLayout(adivwith the classlayoutthat rendersSidebarthenArticle). Apprenders aLayoutand nothing else.
Constraints
App's JSX must contain only the Layout component.
Example
The preview shows the menu with three items and, after it, the Welcome article.
Why it works
Layout groups the two parts so that App stays one line, and each level of the tree only knows about the level directly below it.
Hints
Hint 1
A component can use other components: Layout can render <Sidebar /> and <Article />.
Hint 2
Give the outer div the class layout, so the CSS-free check can find it.
Solution
Show one correct solution (try it yourself first)
function Sidebar() {
return (
<aside>
<h2>Menu</h2>
<ul>
<li>Home</li>
<li>Lessons</li>
<li>Practice</li>
</ul>
</aside>
);
}
function Article() {
return (
<article>
<h2>Welcome</h2>
<p>Pick a lesson to start.</p>
</article>
);
}
function Layout() {
return (
<div className="layout">
<Sidebar />
<Article />
</div>
);
}
export default function App() {
return <Layout />;
}