What is a React component?
Options
- A CSS file with styles for the pages of the app
- A reusable UI piece, usually a function returning JSX (Correct option)
- A database table for storing the state of the UI
- 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.