Create custom events for component communication:
// Create and dispatch
const event = new CustomEvent("userLogin", {
detail: { userId: 123 }
});
element.dispatchEvent(event);
// Listen
element.addEventListener("userLogin", (e) => {
console.log(e.detail.userId);
});
Custom events let components communicate without tight coupling.