React Props Explained for Beginners: Pass Data Easily
What are props in React? Learn how to pass data to components with simple examples, children, default values and common mistakes. Perfect for beginners.
What are props in React? Learn how to pass data to components with simple examples, children, default values and common mistakes. Perfect for beginners.
What are props in React? Props (short for "properties") are the way you send data from one component to another. Think of them like the settings you give to a function. You write them like HTML attributes, and the component reads them and shows something different each time. This guide explains props from zero, with small examples you can copy.
You do not need any React experience beyond knowing that a component is a reusable piece of a web page. If that is new, read our guide on what a React component is first.
New to components? Start with this simple guide first.
What is a React component?A component is a function that returns some HTML-like code (called JSX). Without props, a component always shows the same thing. With props, you can reuse one component many times with different data.
A real-life example: a greeting card template. The layout is always the same, but you change the name on each card. The template is the component. The name is the prop.
function Welcome() {
return <h1>Hello, Sam!</h1>;
}
export default Welcome;Line 1 creates a component named Welcome. Line 2 returns the heading to show on the page. Line 5 exports it so other files can use it. The problem: it can only ever greet Sam.
function Welcome(props) {
return <h1>Hello, {props.name}!</h1>;
}
function App() {
return (
<div>
<Welcome name="Sam" />
<Welcome name="Priya" />
<Welcome name="Lucas" />
</div>
);
}
export default App;In line 1, the component now accepts one input called props. React fills it in for you. It is an object that holds everything you passed in. In line 2, {props.name} reads the name value; curly braces let you put JavaScript inside JSX. In lines 8 to 10, we use Welcome three times and pass a different name each time, just like an HTML attribute. The page shows three different greetings from one component.
Typing props.name over and over gets tiresome. Most developers use destructuring, a JavaScript shortcut that pulls values out of an object into variables.
function Welcome({ name }) {
return <h1>Hello, {name}!</h1>;
}The curly braces in the parentheses say: take the name value out of the props object. Now you can write {name} directly. It works exactly the same as before, just shorter.
Strings go in quotes. Everything else (numbers, true/false, arrays, objects, functions) goes inside curly braces.
function ProfileCard({ name, age, isOnline, hobbies }) {
return (
<div>
<h2>{name}</h2>
<p>Age: {age}</p>
<p>{isOnline ? "Online" : "Offline"}</p>
<ul>
{hobbies.map((hobby) => (
<li key={hobby}>{hobby}</li>
))}
</ul>
</div>
);
}
function App() {
return (
<ProfileCard
name="Maria"
age={28}
isOnline={true}
hobbies={["Reading", "Hiking", "Chess"]}
/>
);
}ProfileCard receives four props. In App, name is a string, so it uses quotes. age, isOnline and hobbies use curly braces because they are a number, a boolean and an array. Inside the card, the ternary (condition ? a : b) shows Online or Offline, and map() turns each hobby into a list item. The key helps React track each item in a list.
| Value type | How to pass it | Example |
|---|---|---|
| String | Quotes | name="Maria" |
| Number | Curly braces | age={28} |
| Boolean | Curly braces | isOnline={true} |
| Array | Curly braces | hobbies={["a", "b"]} |
| Function | Curly braces | onSave={handleSave} |
What if someone forgets to pass a prop? You can give it a default value so the page still looks right.
function Button({ label = "Click me", color = "blue" }) {
return <button style={{ background: color }}>{label}</button>;
}
// <Button /> -> Click me, blue
// <Button label="Save" /> -> Save, blueWriting = "Click me" after a name sets the fallback. If the prop is passed, React uses it. If not, React uses the default. The double curly braces in style={{ ... }} are one pair for JavaScript and one pair for the style object.
Anything you put between a component's opening and closing tags arrives as a prop called children. This is great for boxes, cards and layouts.
function Card({ title, children }) {
return (
<div className="card">
<h3>{title}</h3>
{children}
</div>
);
}
function App() {
return (
<Card title="Tip of the day">
<p>Drink more water.</p>
</Card>
);
}Card takes a title and children. In App, the paragraph between the Card tags becomes children, and Card prints it inside its box at the {children} spot. You can now wrap any content in the same styled card.
This is the most important rule: a component must never change its own props. Props flow one way, from parent to child, like a gift. The child can use it but not alter it.
function Welcome({ name }) {
// Wrong: name = "Someone else";
return <h1>Hello, {name}!</h1>;
}The commented line shows what not to do. If a value needs to change over time, use state instead. State belongs to the component itself, while props come from outside.
Not sure when to use props and when to use state? This post explains the difference with examples.
Read: Props vs StateProps are values you pass into a component so it can show different content. They work like function arguments. The parent component sends them, and the child component reads them.
Props come from outside the component and cannot be changed by it. State lives inside the component and can change over time, which makes the screen update. Use props to pass data in and state to remember data that changes.
No. Props are read-only in React. If you need a value that changes, store it in state or ask the parent to send a new prop value.
Put the function name in curly braces, like onSave={handleSave}. The child component can then call it, for example when a button is clicked. This is how a child tells its parent that something happened.
It is a special prop that contains whatever you place between a component's opening and closing tags. It lets you build wrapper components such as cards, modals and layouts that can hold any content.
Want help building a React app or learning faster? Talk to the Fepiq team.
Contact FepiqOccasional, no-fluff notes on shipping modern software — startups, automation, Laravel, Shopify and more. No spam, unsubscribe anytime.
Keep reading
Learn SQL AND, OR and NOT operators with simple examples. See how to combine conditions in WHERE and avoid the common mistakes beginners make.
Learn JavaScript template literals with simple examples: backticks, ${} variables, and multi-line strings. A beginner-friendly guide you can copy and run.
Let's build something
Book a free discovery call. We'll listen, ask sharp questions, and send you a proposal within 3 business days.