In web-components, similar to React, we send data down, and events up.
With React, it's common to send an event into a child component as an attribute. For example:
<CustomComponent handleClick={this.handleClick}></CustomComponent>
I've learned that it's also possible to do this with LitElement web-components:
<custom-component .handleClick=${this.handleClick}></custom-component>
However, many sources I've read say to use a custom event from within the component without ever mentioning attribute callbacks:
this.dispatchEvent(
new CustomEvent('some-custom-event', {
bubbles: true,
composed: true,
detail: {
data: someData,
},
})
);
My question is, why is it preferred to dispatch a custom event rather than send a callback to the web component as an attribute? Is it convention or is there a strong reason that I just can't find?