atomico
Version:
Atomico is a small library for the creation of interfaces based on web-components, only using functions and hooks.
19 lines (17 loc) • 469 B
JavaScript
import { useHost } from "../create-hooks.js";
import { dispatchEvent } from "../../element/set-prototype.js";
/**
* @type {import("core").UseEvent}
*/
export const useEvent = (type, eventInit = {}) => {
const ref = useHost();
if (!ref[type]) {
ref[type] = (detail = eventInit.detail) =>
dispatchEvent(ref.current, {
type,
...eventInit,
detail
});
}
return ref[type];
};