function ProductPage({ product, addToCart }) { | |
// ✅ Good: Event-specific logic is called from event handlers | |
function buyProduct() { | |
addToCart(product); | |
showNotification(`Added ${product.name} to the shopping cart!`); | |
} | |
function handleBuyClick() { | |
buyProduct(); | |
} | |
function handleCheckoutClick() { | |
buyProduct(); | |
navigateTo('/checkout'); | |
} | |
// ... | |
} |