Your Second Component
Part of the Fundamentals section of Coddy's React journey — lesson 12 of 42.
Let's extract a component. You can define as many components as you like in one file: smaller ones above, App at the bottom:
function Welcome() {
return <p>Glad you're here!</p>;
}
export default function App() {
return (
<div>
<Welcome />
</div>
);
}Only App carries export default: it's the entry component that main.jsx renders. The others are internal helpers.
Challenge
BeginnerCreate your first standalone component.
- Define a component called
Header(capital H!) aboveApp. It returns an<h1>withid="page-title"and the textMy Blog. - Render it inside App's
<div>with<Header />.
Try it yourself
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div id="root"></div>
<script type="module" src="main.jsx"></script>
</body>
</html>This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
2JSX Expressions
Curly BracesMath in BracesBraces in AttributesCalling Functions in JSXRecap: JSX Expressions5State & Events
What Is State?Click CounterCount in StepsToggle with StateIndependent StateRecap: State & Events8Project: Profile Card
Step 1: Card StructureStep 2: Card with PropsStep 3: Like ButtonStep 4: Follow Toggle