Lesson 3 of 3010%
(Progress persistence is disabled until Phase 9)
React
Beginner
Creating Your First Component
Learn how to write a basic React component.
A React component is simply a JavaScript function that returns markup.
function Greeting() {
return <h1>Hello, BrowserCode!</h1>;
}
Rules of Components
- Capitalized Names: Component function names must start with a capital letter (e.g.,
Greeting, notgreeting). - Return Markup: They must return JSX.
- Export/Import: In a real project, you would export your component to use it in other files.
You can then use this component inside another component just like an HTML tag:
function App() {
return (
<div>
<Greeting />
</div>
);
}
Try It Yourself