import { Host, useEvent } from "atomico";
type DetailClickButton = {id: number};
// π declaration to associate event to JSX/TSX
function component():Host<{onclickButton: CustomEvent<DetailClickButton>}> {
// π type for detail
const dispatchEvent = useEvent<DetailClickButton >("clickButton", {
bubbles: true,
composed: true,
});
return (
<host>
<button onclick={() => {
// π Detail
dispatchEvent({id:100});
}}>button</button>
</host>
);
}
Event customization
The second parameter of useEvent allows customizing the behavior of the even:
interface EventInit {
// Allows the event to be dispatched upstream to the node's containers.
bubbles?: boolean;
// Allows the event to traverse the shadowDOM event capture.
composed?: boolean;
// Allows the event to be canceled.
cancelable?: boolean;
// Allows customizing the event builder, ideal for event instance-based communication.
base?: Event | CustomEvent;
}