Components Introduction
Components are the building blocks of a React app. Each component is a function that returns markup for one part of the page.
A small component
Greeting is one component. It returns a heading.
function Greeting() {
return <h1>Hello from Greeting!</h1>
}Names start with a capital letter
React reads a lowercase tag as an HTML tag.
function Greeting() {
return <h1>Hello!</h1>
}Example
export default function Greeting() {
return <h1>Hello from Greeting!</h1>
}Key points
- A component name starts with a capital letter.
- A component returns the markup for one part of a page.
- Each component has its own name.
- Small components keep each part of a page easy to read.
In this example, Greeting is a small component. It returns a heading. The name starts with a capital letter. React renders the heading on the page.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What is a component in React?