项目作者: NekR

项目描述 :
Preact delegate DOM events
高级语言: JavaScript
项目地址: git://github.com/NekR/preact-delegate.git
创建时间: 2017-03-02T23:11:58Z
项目社区:https://github.com/NekR/preact-delegate

开源协议:MIT License

下载


preact-delegate

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

Install

  1. 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:

  1. import { Component } from 'preact';
  2. import { DelegateContainer, DelegateElement } from 'preact-delegate';
  3. class MyComponent extends Component {
  4. constructor(...args) {
  5. super(...args);
  6. this.onClick = (e) => {
  7. console.log(e.target);
  8. };
  9. }
  10. render({ items }) {
  11. return <DelegateContainer>
  12. <div class="my-component">
  13. {items.map(item => (
  14. <div class="my-item">
  15. <DelegateElement click={this.onClick}>
  16. <button type="button" class="my-button">{ item.text }</button>
  17. </DelegateElement>
  18. </div>
  19. ))}
  20. </div>
  21. </DelegateContainer>
  22. }
  23. }

LICENSE

MIT