This code violates DRY by duplicating the card structure and styling across components. A better approach would be to create a reusable Card component:
function Card({ title, content, className = '' }) {
return (
<div className={`card p-4 shadow rounded-lg ${className}`}>
<h2 className="text-xl font-bold mb-2">{title}</h2>
<p className="text-gray-600 mb-4">{content}</p>
</div>
);
}
function UserProfile({ user }) {
return <Card title={user.name} content={user.bio} />;
}
function ProductCard({ product }) {
return <Card title={product.name} content={product.description} />;
}
This approach:
1. Eliminates duplicate structure and styling
2. Makes it easier to maintain consistent styling
3. Allows for easy modifications across all cards
4. Provides flexibility through props