Repaso
EspaƱol

What is a React component?

Options

  1. A CSS file with styles for the pages of the app
  2. A reusable UI piece, usually a function returning JSX (Correct option)
  3. A database table for storing the state of the UI
  4. A server route that returns HTML for the pages

Answer

A reusable piece of UI, usually a function that receives props and returns JSX

Why

React apps are built from components, like Lego blocks: <Header />, <ProductCard />, <Button />.

A component is a function that returns JSX, HTML-like syntax describing what to show. React calls it again whenever its data changes and updates the screen.

function Greeting({ name }) {
  return <h1>Hello, {name}!</h1>;
}

<Greeting name="Ana" />

Remember

Component = function that returns UI.

Key terms

Practice this question in Repaso