React: Your first component

Write the App component of a page, the first step of every React app.

What to build

An App component that shows a heading and a paragraph.

Requirements

  • App returns a main element containing an h1 with the text Welcome to React and a p with the text Components are functions that return JSX.
  • Keep export default function App().

Constraints

Use JSX only; do not change the page with document methods.

Example

The preview shows the heading "Welcome to React" with the sentence under it.

Why it works

App is the top of the component tree: whatever JSX it returns is what React puts into the page.

Hints

Hint 1

A component returns JSX: return (<main> ... </main>);

Hint 2

Write the heading and the paragraph inside one main element.

Solution

Show one correct solution (try it yourself first)
export default function App() {
  return (
    <main>
      <h1>Welcome to React</h1>
      <p>Components are functions that return JSX.</p>
    </main>
  );
}

Lesson: What React is: components and rendering →