atomico-hooks-events

Dispatch and listen to typed DOM and custom events in Atomico components.

1.3k|44|Updated Aug 25, 2018
One-click install
npx skills add https://github.com/atomicojs/atomico --skill atomico-hooks-events
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: atomico-hooks-events
Source: https://github.com/atomicojs/atomico/tree/main/.agents/skills/atomico-hooks-events
Command: npx skills add https://github.com/atomicojs/atomico --skill atomico-hooks-events

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Managing custom events and DOM listeners across web components is error-prone and verbose, leading to stale handlers, untyped payloads, and fragile cross-component communication. This Skill documents the useEvent and useListener hooks plus the event() prop helper to provide a consistent, typed approach for dispatching and listening to events within Atomico components while ensuring proper cleanup and predictable timing.

Core Features & Use Cases

  • Dispatch Typed Events: useEvent creates a cached dispatcher that sends typed CustomEvent payloads from the host element, or calls matching event props when present.
  • Ref-based Listeners with Auto-cleanup: useListener attaches handlers to referenced elements, updates to the latest handler, and removes listeners when refs change or the component unmounts.
  • Prop-based Event Integration: event() declares props that act as both internal dispatchers and external callback listeners, enabling parent callbacks and JSX on-prefixed listeners.
  • Use Cases: Build interactive UI elements that emit structured events to parents, implement pub/sub patterns across components, and attach stable handlers to internal or external DOM nodes.

Quick Start

Use useEvent to dispatch typed CustomEvents and use useListener to attach and auto-cleanup a ref-based handler inside an Atomico component.

Frequently Asked Questions about atomico-hooks-events

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I dispatch typed custom events from Atomico web components?

You can dispatch typed custom events from Atomico web components using the useEvent hook, which creates a cached dispatcher to send typed CustomEvent payloads from the host element or invoke matching event props.

How do I attach DOM event listeners to web components with automatic cleanup?

To attach DOM event listeners with automatic cleanup, the useListener hook binds handlers to referenced elements, continuously updates to the latest handler, and removes listeners when refs change or the component unmounts.

What is the best way to implement pub/sub communication across Atomico components?

The best way to implement pub/sub communication across Atomico components is using useEvent for dispatching structured events and useListener for receiving them, ensuring predictable timing and auto-cleanup of listeners.

Can I use parent callback props for event handling in Atomico?

Yes, you can use parent callback props in Atomico by leveraging the event() helper, which declares props that act as both internal dispatchers and external callback listeners for JSX on-prefixed event integration.

Does the atomico-hooks-events Skill require a specific Atomico version?

Yes, the atomico-hooks-events Skill requires Atomico version 1.79 or higher to properly support typed event payloads, prop-based event integration, and layout-phase attachment timing for web components.

Why do my custom event listeners leave stale handlers when components unmount?

Custom event listeners leave stale handlers when manually attached without cleanup logic; useListener solves this by automatically removing listeners when refs change or the Atomico component unmounts.