Accessing Props in the Component
What you'll learn: How to actually use the prop values you've passed into a component.
Once props arrive in your component, you need to extract and use them. React bundles all props into a single object called props, and you access individual values using dot notation: props.propName.
The Props Object
When you pass props to a component, React collects them into an object:
// When you write:
<Greeting name="Alice" age={25} />
// React creates:
// props = { name: "Alice", age: 25 }
Inside your component function, you receive this props object as the first parameter:
function Greeting(props) {
return <h1>Hello, {props.name}!</h1>
}
Notice props.name — you're accessing the name property from the props object.
Using Multiple Props
You can access as many props as you need:
function UserCard(props) {
return (
<div>
<h2>{props.name}</h2>
<p>Age: {props.age}</p>
<p>City: {props.city}</p>
</div>
)
}
Destructuring Props
You can destructure the props object directly in the function parameter to avoid repeating props. everywhere:
function Greeting({ name, age }) {
return <h1>Hello, {name}! You are {age}.</h1>
}
This extracts name and age directly from the props object. Both approaches work identically — destructuring is just cleaner when you have multiple props.
Think of It Like This
Props are like a package delivered to your door. You need to open it (props.name) or unpack it ({ name }) to use what's inside.
Key Takeaway: Access props using props.propName or destructure them in the function parameter for cleaner code — both give you the values passed from the parent component.