preact-delegate

1.1.1 • Public • Published

preact-delegate

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

Install

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:

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 <DelegateContainer>
      <div class="my-component">
        {items.map(item => (
          <div class="my-item">
            <DelegateElement click={this.onClick}>
              <button type="button" class="my-button">{ item.text }</button>
            </DelegateElement>
          </div>
        ))}
      </div>
    </DelegateContainer>
  }
}

LICENSE

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.1
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.1
    1
  • 1.1.0
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i preact-delegate

Weekly Downloads

1

Version

1.1.1

License

MIT

Last publish

Collaborators

  • nekr