Common Destructuring Antipatterns
You'll learn to recognize and avoid destructuring patterns that harm code readability and maintainability.
Why Destructuring Can Go Wrong
Destructuring props is powerful, but it's easy to overuse or misuse. The goal is clarity, not just brevity. When destructuring makes your code harder to understand or trace, you've crossed into antipattern territory.
Antipattern 1: Over-Destructuring Everything
function UserProfile({
name,
email,
age,
city,
country,
zipCode,
phoneNumber,
profilePicture,
bio,
status
}) {
// Ten destructured params makes the signature overwhelming
return <div>{name} from {city}</div>;
}
When you destructure 8+ props, the function signature becomes unreadable. Consider using props object directly or destructuring only what you need immediately.
Antipattern 2: Unclear Naming
function Button({ children: text, onClick: handler, className: styles }) {
// Renaming during destructuring loses semantic meaning
return <button onClick={handler} className={styles}>{text}</button>;
}
Renaming props while destructuring (children: text) obscures what the component actually receives. Future readers won't understand the original prop names.
Antipattern 3: Losing Prop Context
function DataDisplay({ data: { id, value, timestamp } }) {
console.log(id); // Where did 'id' come from? props.data is invisible now
return <div>{value}</div>;
}
Deep nested destructuring removes the context that id came from a data object. This makes debugging and tracing data flow significantly harder.
Better Approach
function DataDisplay({ data }) {
const { id, value, timestamp } = data;
// Now it's clear these come from props.data
return <div>{value}</div>;
}
Key Takeaway: Destructure for readability, not brevity—if it makes props harder to trace or understand, you've gone too far.