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

  1. Capitalized Names: Component function names must start with a capital letter (e.g., Greeting, not greeting).
  2. Return Markup: They must return JSX.
  3. 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

Lesson Progress

Take QuizBuild a React Project