React Foundations · Rendering & JSX

Your first component

Your first component

A page is made of pieces: a heading, a paragraph, a button. React lets you describe one piece as a function, then render that function wherever you need it.

That function is a component. A React component returns JSX — a syntax that looks like HTML but lives inside your JavaScript. When React renders a component, it calls the function and turns the returned JSX into real DOM elements.

Two rules turn a function into a component:

  1. Its name starts with a capital letter, so React can tell it apart from a plain HTML tag.
  2. It returns JSX (or null).
export function App() {
  return <h1>Hello, React!</h1>;
}

The export keyword makes the component importable. The Test for this Lesson imports App from App.jsx, renders it, and inspects the result. The component must be exported with exactly that name.

JSX elements map to HTML: <h1> becomes a level-one heading, <p> a paragraph. React Testing Library finds elements by their role, so the element you pick matters. A <p> and an <h1> look similar in source but are different roles in the accessibility tree.

Your job is to render a level-one heading with the exact text the Challenge asks for.

Challenge

The page is showing a paragraph where a heading belongs. Turn that piece into a real heading: export an App component from App.jsx that renders a level-one heading (<h1>) whose text is exactly Hello, React!.

The Test renders your component and looks for a heading with that text. The starter renders a paragraph instead, so the Test fails. Change the element to a heading and keep the text.

App.jsx
export function App() {
  return <p>Hello, React!</p>;
}

No test run yet

The Test is hidden. Run it to check the Challenge — you only see the result, never the test source.