@zeix/ui-element
Version:
UIElement - a HTML-first library for reactive Web Components
59 lines (30 loc) • 1.04 kB
Markdown
[**@zeix/ui-element**](../README.md)
***
[@zeix/ui-element](../globals.md) / on
# Function: on()
> **on**\<`K`, `P`, `E`\>(`type`, `handler`, `options`): [`Effect`](../type-aliases/Effect.md)\<`P`, `E`\>
Defined in: [src/core/events.ts:147](https://github.com/zeixcom/ui-element/blob/1e5ebee179adfc4619d3d0e9d2b864d1e97ba797/src/core/events.ts#L147)
Effect for attaching an event listener to an element.
Provides proper cleanup when the effect is disposed.
## Type Parameters
### K
`K` *extends* `string`
### P
`P` *extends* [`ComponentProps`](../type-aliases/ComponentProps.md)
### E
`E` *extends* `Element` = `HTMLElement`
## Parameters
### type
`K`
Event type
### handler
[`EventHandler`](../type-aliases/EventHandler.md)\<`P`, `E`, [`EventType`](../type-aliases/EventType.md)\<`K`\>\>
Event handler function
### options
Event listener options
`boolean` | `AddEventListenerOptions`
## Returns
[`Effect`](../type-aliases/Effect.md)\<`P`, `E`\>
Effect function that manages the event listener
## Since
0.14.0