Course contentsShow
← React
Lesson 214 of 2,3967. Props FundamentalsFree lesson

Receiving Props: The Props Object

Function components receive props as their first parameter, an object containing all passed prop key-value pairs.

Receiving Props: The Props Object

What you'll learn: How function components automatically receive all passed props bundled together as a single object parameter.

The Props Parameter

When you define a function component, React automatically passes it one argument: an object containing all the props that were passed to that component. By convention, we name this parameter props.

function Greeting(props) {
  // props is an object: { name: "Alice", age: 25 }
  return <h1>Hello, {props.name}!</h1>;
}

// Usage:
<Greeting name="Alice" age={25} />

Understanding the Props Object

Think of the props object like a package delivery: when someone sends your component multiple items (props), React bundles them all into one box (the props object) for convenient handling. Each prop becomes a key-value pair inside that object.

function UserCard(props) {
  console.log(props); 
  // { username: "john_doe", followers: 150, verified: true }
  
  return (
    <div>
      <h2>{props.username}</h2>
      <p>Followers: {props.followers}</p>
      {props.verified && <span>✓ Verified</span>}
    </div>
  );
}

// Usage:
<UserCard username="john_doe" followers={150} verified={true} />

Accessing Prop Values

You access individual prop values using dot notation: props.propertyName. This is standard JavaScript object property access—nothing React-specific here.

If a prop wasn't passed, accessing it returns undefined, just like accessing any non-existent object property.

function Welcome(props) {
  return <p>Welcome, {props.name || 'Guest'}</p>;
}

Key Takeaway: Function components receive props as their first parameter—an object where each passed prop becomes a key-value pair accessible via props.keyName.