🎓 A1Learner
🔍
0 of 50 lessons completed

Your First React Component

A React component is a JavaScript function that returns markup. The function name starts with a capital letter.

A simple component

App is a function. It returns one heading.

function App() {
  return <h1>Hello from App!</h1>
}

Example

export default function App() {
  return <h1>Hello from App!</h1>
}

Key points

  • Markup is the HTML-like text that describes what shows on the page.
  • The return statement sends the markup back from the function.
  • A capital letter tells React that the name is a component.
  • App is the usual name for the first component of a project.

In this example, App is a JavaScript function. The function returns a heading. The heading reads Hello from App! React shows the heading on the page.

Note

A lowercase name would not work as a component name.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

What does a React component return?