Complete the code to render the
function Header() {
return <h1>Welcome!</h1>;
}
function App() {
return (
<div>
[1]
</div>
);
}Use
Complete the code to pass a 'title' prop from to
function Header(props) {
return <h1>[1]</h1>;
}
function App() {
return <Header title="Hello!" />;
}Use props.title to access the 'title' prop inside the Header component.
Fix the error in the code to correctly render children inside <Wrapper>.
function Wrapper(props) {
return <div>[1]</div>;
}
function App() {
return (
<Wrapper>
<p>Content</p>
</Wrapper>
);
}Use props.children to render the nested content inside the Wrapper component.
Fill both blanks to create a component that wraps content with a section and a class.
function SectionWrapper(props) {
return <section className=[1]>[2]</section>;
}
function App() {
return (
<SectionWrapper className="highlight">
<p>Important info</p>
</SectionWrapper>
);
}Use props.className for the class attribute and props.children to render nested content.
Fill all three blanks to create a component that renders a list of items passed as props.
function ItemList({ [1], [2] }) {
return (
<ul>
{items.map((item, index) => (
<li key=[3]>{item}</li>
))}
</ul>
);
}
function App() {
const items = ['Apple', 'Banana', 'Cherry'];
return <ItemList items={items} />;
}Destructure 'items' and 'index' from props and use 'index' as the key in the list.