Component Props and Read-Only Data Flow0%

Component Props and Read-Only Data Flow

Beginner12 min read•Updated: Jul 11, 2026
Study MaterialsCheatsheet

Component Props and Read-Only Data Flow

1. What Are Props?

In React, props (short for "properties") are the mechanism by which components communicate with each other. Just as HTML elements accept attributes to customize their behavior (<a href="https://example.com">), React components accept props passed down from parent components.

Props can be any valid JavaScript value: strings, numbers, booleans, objects, arrays, functions (callbacks), or even other React elements.

JSX
// Parent component passing props
function Dashboard() {
return (
<div className="dashboard-grid">
<UserCard
name="Ananya Roy"
role="Frontend Architect"
yearsExperience={6}
isActive={true}
/>
</div>
);
}
 
// Child component receiving props object
function UserCard(props) {
return (
<div className="card">
<h3>{props.name}</h3>
<p>Role: {props.role}</p>
<p>Experience: {props.yearsExperience} years</p>
<span className={props.isActive ? 'badge-green' : 'badge-gray'}>
{props.isActive ? 'Active' : 'Offline'}
</span>
</div>
);
}

2. Unidirectional Top-Down Data Flow

React enforces strict unidirectional (one-way) data binding:

  • Data flows strictly from parent components down to child components.
  • A child component has no built-in way to directly mutate or reassign the props given to it by its parent.
  • If a child needs to inform the parent of an event or change, the parent passes a callback function down as a prop, which the child invokes.
Output
Parent Component (Source of Truth: state = "dark")
│
▼ (passes prop theme="dark")
Child Component (Renders UI based on theme prop)

3. Props are Read-Only (Immutable)

A cardinal rule in React engineering is: Components must never mutate their own props.

In JavaScript terms, props are treated as frozen, read-only values:

JSX
// ❌ Anti-pattern: Modifying props directly is forbidden!
function Profile(props) {
props.name = props.name.toUpperCase(); // Mutates prop object!
props.viewCount += 1; // Mutates prop object!
 
return <div>{props.name} ({props.viewCount})</div>;
}
 
// ✅ Correct Pattern: Derive new values or declare local variables
function Profile(props) {
const formattedName = props.name.toUpperCase();
const nextCount = props.viewCount + 1;
 
return <div>{formattedName} ({nextCount})</div>;
}

If React permitted components to modify incoming props, child components could unexpectedly corrupt parent data structures, creating chaotic debugging nightmares across large applications.

4. Passing Non-String Props

Remember to enclose non-string values (numbers, booleans, objects, arrays) in curly braces:

JSX
// Strings can use regular quotes
<Badge text="Pro Member" />
 
// Numbers, booleans, objects, and arrays MUST use curly braces
<Badge count={42} isVerified={true} settings={{ theme: 'dark' }} tags={['js', 'react']} />

Interactive Quiz

Practice Quiz

Question 1
What are props in React?
Question 2
Why is mutating a prop directly inside a child component forbidden in React?
Question 3
How should a child component inform its parent that a user clicked a button?
Question 4
Which prop assignment passes the number 25 as an actual JavaScript numeric type?
Question 5
What data types can be passed as props in React?
Next Lesson

Destructuring Props and Default Prop Values

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext