Your First Component
Part of the Fundamentals section of Coddy's React journey — lesson 2 of 42.
Time to write your first component. Look at App.jsx. It's a function that returns JSX:
export default function App() {
return (
<div>
</div>
);
}Right now it returns an empty <div>, so the preview is blank. Whatever JSX you put inside gets rendered (headings, paragraphs, buttons, anything):
<h1 id="title">Hello, React!</h1>Notice the id attribute: it works just like in HTML, and our tests use ids to find your elements. The other two files are the app's plumbing: index.html hosts the app and main.jsx mounts App into the page. They're locked. App.jsx is where you work.
Challenge
BeginnerMake your app greet the world.
- Inside the
<div>inApp.jsx, add an<h1>withid="title". - Its text must be exactly
Hello, React!
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