preact-delegate
Preact delegate DOM events
Last updated 3 years ago by nekr .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install preact-delegate 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.1.1                                ...           latest (3 years ago)

3 Versions

  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 0
Last Month 3
Dependencies (0)
None
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |