Skip to main content

CustomEvent

Explore practical guides and implementation patterns for this topic.

Posts

Lightning Web Components

🗣️ Component Communication in LWC: @api, Events & LMS Explained

💬 In plain words: In Lightning Web Components (LWC), there are three distances your data can travel, and three exact tools to use. To talk down (Parent → Child), use @api properties. To talk up (Child → Parent), fire a CustomEvent . To talk to strangers (components anywhere else on the page), use the Lightning Message Service (LMS), which acts like a page-wide radio channel. 📌 Example: E-Commerce Store A user clicks "Add to Cart" on a product tile (Child). The tile fires a CustomEvent('addtocart') upwards. The main product grid (Parent) catches that event, updates its internal state, and passes the new cart count down to the cart badge (another Child) via an @api property. Meanwhile, a mini-cart widget living totally separately in the page header listens to a Lightning Message Service (LMS) channel to know the cart was updated.
Read article