Destructuring vs Direct Access Tradeoffs
You'll learn when to destructure props versus accessing them directly with props.x, and why both patterns have their place.
The Two Patterns
You've seen both approaches for working with props:
// Destructuring in parameters
function Greeting({ name, age }) {
return <h1>Hello, {name}! You are {age}.</h1>;
}
// Direct access
function Greeting(props) {
return <h1>Hello, {props.name}! You are {props.age}.</h1>;
}
Both work identically, but each has advantages depending on the situation.
When Destructuring Shines
Few props (1-4): Destructuring makes code cleaner and more readable. You immediately see what props the component expects without scrolling through the body.
Frequent prop usage: If you reference name ten times, writing name beats props.name every time.
Default values: Destructuring lets you set defaults inline: { name = 'Guest' }.
When Direct Access Wins
Many props (5+): Destructuring parameters with 10 props creates a cluttered function signature. props.x keeps the signature clean.
Namespace clarity: Sometimes props.title is clearer than just title — you know it came from outside, not a local variable.
Passing props through: If you're spreading remaining props ({...props}), you need the props object anyway.
Rare usage: If you only use a prop once deep in the function, destructuring it upfront feels premature.
Think of It Like a Toolbox
Destructuring is like laying out your tools on a workbench — great when you'll use them repeatedly. Direct access is like keeping tools in the box — better when you only need one or two things, or have too many to lay out neatly.
Key Takeaway: Use destructuring for small, frequently-used prop sets; use direct access for many props, occasional usage, or when you need the props object itself. Both are valid, and mixing them in the same codebase is perfectly fine.