Component Communication:Props

Discover how to build reusable and dynamic components by passing data from parent to child.

Lesson ProgressStep 1 of 9

Parent & Child

Parent
Child
Parentname="Alex"
Child
Parentname="Alex"
Child

Hello, Alex

Parentname="Alex"
Child

Hello, Alex

Parentname="Alex", age=30
Child

Alex is 30

Parent
Child

Alex is 30

Child

Maria is 25

🎉

0 EXP

Hello! Let's learn how React components communicate. The most common way is with 'props'.

// Welcome to the React Props simulator!

What Are Props?

**Props** (short for "properties") are the main way to pass data into React components. Think of them as arguments to a function. If a component is a function that returns UI, props are the arguments that tell that function *what* UI to return.

The single most important rule is: **Props are read-only**. A component must *never* modify the props it receives. This ensures a predictable, one-way data flow.

System Check

What is the golden rule of props?

Advanced Holo-Simulations

0 EXP

Log in to unlock these advanced training modules and test your skills.


Achievements

🎁
Prop Passer

Successfully pass a prop from a parent to a child.

📥
Prop Receiver

Correctly receive and use a prop in a child component.

Destructure Whiz

Use prop destructuring for cleaner code.

Mission: Pass the Prop

Modify `UserCard` to pass a `name` prop to the `Profile` component. Then, modify `Profile` to receive and display that name.

A.D.A. Feedback:

> System integrity looks stable. Code is valid.

Challenge: Order the Data Flow

Drag the component parts into the correct logical order, from the data's origin (Parent) to its final use (in the Child).

function Child({ message }) { ... }
function Parent() { ... }
return <p>{message}</p>

Challenge: Complete the Syntax

Fill in the blanks to correctly destructure the `title` prop and display it.

function Article() {
return <h2>{title}</h2>;
}

Consult A.D.A.

Community Holo-Net

Peer Project Review

Submit your "Pass the Prop" project for feedback from other Net-Runners.

Props: The Core of Component Communication

In React, an application is a tree of components. But how do these components talk to each other? The primary way is through **props**. "Props" is short for "properties," and they are the mechanism for passing data from a parent component down to a child component.

Think of components as JavaScript functions. Props are their arguments. Just as a function takes arguments to change its behavior, a component takes props to change what it renders.

The Golden Rule: Unidirectional Data Flow

React enforces a strict rule: **data flows one way**, from parent to child. This is called "unidirectional data flow." A parent component can pass data down to its child as props, but a child component **cannot** modify the props it receives. Props are **read-only** (immutable) from the child's perspective.

This rule makes your application far more predictable. When you see an error in the UI, you can trace the data back up the component tree to its source (often a parent's state) without worrying that a child component somewhere modified the data unexpectedly.

Passing and Receiving Props: The Syntax

Passing props looks just like adding attributes to an HTML tag. To receive them, the child component accepts a single argument: an object that contains all the props.

1. The Parent Component (Passing)

function App() {
  // Data to pass
  const userName = "Sasha";

  return (
    <UserProfile 
      name={userName} 
      age={28} 
      isAdmin={true} 
    />
  );
}
  • Strings can be passed with quotes: `name="Sasha"`
  • Variables, numbers, booleans, and objects MUST use curly braces: `age=28`

2. The Child Component (Receiving)

// Option A: The 'props' object
function UserProfile(props) {
  return (
    <div>
      <p>Name: {props.name}</p>
      <p>Age: {props.age}</p>
    </div>
  );
}

// Option B: Destructuring (Recommended)
function UserProfile({ name, age, isAdmin }) {
  return (
    <div>
      <p>Name: {name}</p>
      <p>Age: {age}</p>
      {isAdmin && <p>Admin User</p>}
    </div>
  );
}

Destructuring is preferred as it's cleaner and makes it obvious what props the component expects.

The Special `children` Prop

There is one special prop that React handles differently: `props.children`. This prop contains whatever you put *between* the opening and closing tags of your component. This is incredibly useful for creating "wrapper" components like cards, modals, or layout elements.

// 1. The Wrapper Component
function Card({ children }) {
  return <div className="card">{children}</div>;
}

// 2. How to use it
<Card>
  <h1>This is the title</h1>
  <p>This paragraph and heading are passed as props.children.</p>
</Card>

Passing Functions as Props (Callbacks)

What if a child needs to communicate *up* to a parent? Since props are read-only, the child can't change the parent's data. Instead, the parent passes a **function** down as a prop. The child can then call this function (a "callback") whenever an event happens, like a button click. This function, which lives in the parent, can then update the parent's state.

Key Takeaway: Props are the foundation of building a component-based UI. They allow you to create reusable, "dumb" components that receive data, and "smart" parent components that manage state and pass that data down.

React Props Glossary

Props
Short for "properties." A JavaScript object of data passed from a parent component to a child component. Props are read-only from the child's perspective.
Unidirectional Data Flow
The core principle in React that data only flows in one direction: from parent components down to child components via props.
Parent Component
A component that renders one or more other components (children) and passes data to them via props.
Child Component
A component that is rendered by a parent and receives data via props.
Destructuring
A JavaScript feature (e.g., `function Child(< name >)`) used to unpack values from objects or arrays. In React, it's the recommended way to access specific props from the `props` object.
`props.children`
A special prop that contains any content nested between a component's opening and closing tags. It allows for component composition.
Callback (Function Prop)
A function passed as a prop from a parent to a child. The child can call this function to communicate an event (like a click) back up to the parent.
Prop Drilling
A common scenario where props are passed down through multiple layers of intermediate components that don't need the prop, just to get it to a deeply nested child. This is often a sign to use Context API or state management.
Default Props
A way to define default values for props, so that a component can run even if a required prop is not provided by the parent. (e.g., `function Child(< name = "Guest" >)`)

About the Author

Author's Avatar

TodoTutorial Team

Passionate developers and educators making programming accessible to everyone.

This article was written and reviewed by our team of web development experts, who have years of experience teaching React and building robust and accessible web applications.

Verification and Updates

Last reviewed: October 2025.

We strive to keep our content accurate and up-to-date. This tutorial is based on the latest React specifications and is periodically reviewed to reflect industry best practices.

External Resources

Found an error or have a suggestion? Contact us!