What Is a React Component? A Beginner's Guide
What is a React component, really? A beginner-friendly guide with copy-pasteable examples that explains components, props, and rendering step by step.
What is a React component, really? A beginner-friendly guide with copy-pasteable examples that explains components, props, and rendering step by step.
A React component is a small, reusable piece of code that describes part of a user interface (UI) — for example, a button, a search bar, or a whole page. You write a component once, and you can reuse it anywhere in your app. In plain words: a component is a JavaScript function that returns HTML-like markup, and React uses that function to draw part of the screen. This guide explains what components are, how to write one, and how they fit together, with small examples you can copy and run.
Think of a web page like a set of building blocks. A navigation bar is one block. A product card is another block. A footer is another block. In React, each of these blocks is a component. A component is just a JavaScript function whose job is to return a piece of UI. React takes what each component returns and puts it on the screen.
Two rules make something a React component: its name starts with a capital letter (like Button, not button), and it returns markup written in JSX — a syntax that looks like HTML but lives inside JavaScript. That's it. Once you have a component, you can reuse it as many times as you like, just like reusing a function.
Here is the smallest possible React component. It shows a greeting on the screen.
function Greeting() {
return <h1>Hello, world!</h1>;
}
export default Greeting;Line by line: function Greeting() defines a normal JavaScript function named Greeting (capital G, so React treats it as a component). The return statement gives back a piece of JSX — here, an h1 heading. export default Greeting makes this component available so other files can import and use it.
Defining a component does nothing by itself — you also need to render it, meaning place it somewhere so React draws it on the page. You use a component the same way you'd use an HTML tag, but with a capital letter.
import Greeting from './Greeting';
function App() {
return (
<div>
<Greeting />
<Greeting />
</div>
);
}import Greeting brings the component into this file. Inside App, writing <Greeting /> renders one copy of it — notice the self-closing slash, just like an HTML img tag. Because App uses <Greeting /> twice, the "Hello, world!" heading appears twice on the page. That's reuse in action.
A static "Hello, world!" is not very useful. Usually you want each copy of a component to show different data — for example, greeting a different person by name. You do this with props (short for "properties"), which work like arguments passed into a function.
function Greeting(props) {
return <h1>Hello, {props.name}!</h1>;
}
// Using it:
<Greeting name="Amara" />
<Greeting name="Diego" />Greeting(props) now accepts one argument, props, which is an object React builds from the attributes you write on the tag. {props.name} inside the JSX inserts the value of that prop — curly braces let you drop plain JavaScript values into markup. So <Greeting name="Amara" /> renders "Hello, Amara!", and <Greeting name="Diego" /> renders "Hello, Diego!" — same component, different output, because the data passed in is different.
Real apps are built by nesting small components inside bigger ones, like putting Lego pieces together. A Card component might contain a Title component and a Button component.
function Card({ title }) {
return (
<div className="card">
<h2>{title}</h2>
<Button label="Learn more" />
</div>
);
}
function Button({ label }) {
return <button>{label}</button>;
}Card({ title }) uses destructuring to pull the title value straight out of props, which is a shortcut for writing props.title everywhere. Inside its returned markup, Card renders a Button component and passes it a label prop. Button then reads that label and shows it as clickable button text. This is how a handful of small components combine into a full page.
You may see older tutorials use "class components" instead of functions. Modern React (and this guide) uses function components — they are shorter, easier to read, and are what the official docs recommend today.
| Function component | Class component (older style) |
|---|---|
| Written as a plain JavaScript function | Written as a JavaScript class |
| Uses hooks like useState for data | Uses this.state and this.setState |
| Recommended for new projects | Mostly found in legacy codebases |
Once components make sense, the next step is learning how they remember information between renders using state.
Read: Props vs State ExplainedA React component is a reusable JavaScript function that returns markup (JSX) describing part of a user interface, like a button or a page section.
A component is the reusable piece of UI itself, while props are the data you pass into a component to customize what it shows. Think of the component as a template and props as the values that fill it in.
They return JSX, which looks like HTML but is actually JavaScript syntax that gets converted into calls React understands. You can also mix in JavaScript expressions using curly braces, like {props.name}.
Yes — this is called nesting, and it's the normal way React apps are built. Small components combine inside larger ones to form full pages.
No. Modern React uses function components with hooks, and that's what almost all new code and tutorials use today. You only need class components if you're maintaining an older codebase.
Components are the foundation everything else in React is built on. Once you're comfortable writing and nesting them, the natural next steps are learning how to pass data with props in more detail and how components store their own data using state.
Want help building a real React app for your business, not just a tutorial project?
Talk to FepiqOccasional, no-fluff notes on shipping modern software — startups, automation, Laravel, Shopify and more. No spam, unsubscribe anytime.
Keep reading
What is an index in SQL? A plain-English guide with copy-paste examples showing how indexes speed up queries and when you actually need one.
Learn JavaScript DOM manipulation for beginners: select elements, change text and styles, and handle clicks with simple, copy-paste code examples.
Let's build something
Book a free discovery call. We'll listen, ask sharp questions, and send you a proposal within 3 business days.