Props, short for properties, are the inputs passed from one component to another. They allow a parent component to send data into a child component. This is how React components become flexible and reusable instead of hardcoded for one single situation.
If components are the building blocks of a React app, props are one of the main ways those blocks communicate. A component can receive text, numbers, arrays, objects, booleans, JSX, or even functions through props.
function UserCard(props) {
return (
<div>
<h3>{props.name}</h3>
<p>Role: {props.role}</p>
</div>
)
}import UserCard from './UserCard'
function App() {
return (
<div>
<UserCard name="Aman" role="Admin" />
<UserCard name="Riya" role="Editor" />
</div>
)
}Instead of writing props.name and props.role repeatedly, developers often destructure props directly in the function parameter.
function UserCard({ name, role }) {
return (
<div>
<h3>{name}</h3>
<p>Role: {role}</p>
</div>
)
}Props can contain many kinds of values, not just strings.
function ProductCard({ name, price, inStock, tags, onBuy }) {
return (
<div>
<h3>{name}</h3>
<p>Price: Rs. {price}</p>
<p>{inStock ? 'In stock' : 'Out of stock'}</p>
<p>Tags: {tags.join(', ')}</p>
<button onClick={onBuy}>Buy Now</button>
</div>
)
}
function App() {
return (
<ProductCard
name="Laptop"
price={65000}
inStock={true}
tags={['electronics', 'featured']}
onBuy={() => alert('Buying product')}
/>
)
}Sometimes a prop is optional. In that case, you can define a default value so the component still behaves correctly when the parent does not provide one.
function Badge({ label, color = 'blue' }) {
return <span className={`badge badge-${color}`}>{label}</span>
}Props should never be changed inside the child component. The parent owns that data. A child can use props, display props, or call a function prop to request a change, but it should not mutate the prop value directly.
A parent component can pass a function to a child. This is how child components notify parents about user actions.
function ChildButton({ onAction }) {
return <button onClick={onAction}>Click Me</button>
}
function App() {
function handleAction() {
alert('Child button clicked')
}
return <ChildButton onAction={handleAction} />
}React uses one-way data flow. This means data moves from parent to child through props. That makes it easier to track where data comes from and which component is responsible for changing it.
| Mistake | Why it is wrong | Better approach |
|---|---|---|
| Changing props inside a child component | Breaks React's one-way data flow | Let the parent update the data |
| Passing too many unrelated props | Makes components harder to understand | Keep component APIs small and focused |
| Using props when local state is needed | Creates awkward data ownership | Use props for external input and state for internal changes |
| Naming props unclearly | Reduces readability | Use descriptive names like onDelete, userName, or isOpen |
Props are one of the most important parts of React because they allow data to move from parent components to child components. They make components dynamic, reusable, and easier to organize. Once you understand props well, it becomes much easier to build components that work cleanly together.
Explore 500+ free tutorials across 20+ languages and frameworks.