Advertisement
Beginner React, Components & JSX

What is a React component and what are the two main types?

Short answer

A component is a reusable piece of the user interface, like a button, a form, or an entire page. Today almost all components are function components, which are plain JavaScript functions that return JSX.

Save React mock interview
Advertisement
AModel answer
A component is a reusable piece of the user interface, like a button, a form, or an entire page. Today almost all components are function components, which are plain JavaScript functions that return JSX. The older type, class components, are rarely used in new code but still exist in some older projects.
function WelcomeMessage({ name }) {
  return <h1>Welcome, {name}</h1>;
}

<WelcomeMessage name="Sarah" />
Real-world example
An online store builds a single ProductCard component and reuses it dozens of times across the homepage, each time simply passing in different product details.
Likely follow-ups
  • What is the difference between a component and a regular HTML element?
  • Why must a component's name always start with a capital letter?
Related topics