Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/NekR/preact-delegate

Preact delegate DOM events
https://github.com/NekR/preact-delegate

delegate dom events preact

Last synced: about 2 months ago
JSON representation

Preact delegate DOM events

Awesome Lists containing this project

README

        

# preact-delegate

Delegate DOM events with Preact (since Preact doesn't do that by default).

## Install

```sh
npm install preact-delegate --save-dev
```

## Usage

Just wrap your root element from where to capture events with `DelegateContainer` and then wrap individual elements which should receive events with `DelegateElement`. See example:

```js
import { Component } from 'preact';
import { DelegateContainer, DelegateElement } from 'preact-delegate';

class MyComponent extends Component {
constructor(...args) {
super(...args);

this.onClick = (e) => {
console.log(e.target);
};
}

render({ items }) {
return


{items.map(item => (


{ item.text }


))}


}
}
```

## LICENSE

[MIT](LICEMSE.md)