0.2.1 • Published 6 years ago

react-attach-handler v0.2.1

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

react-attach-handler

React attach event handlers to targets.

Installation

Download node at nodejs.org and install it, if you haven't already.

npm install react-attach-handler --save

Why?

This module provides a reactjs way to bind events to global targets. It uses native React lifecycle to bind and unbind events.

Props

  • children, Element, default null.
  • target, (required) String or Object, default ''.
  • events, (required) Function or Object,
    • If events is an Object its accepts capture, passive debounce & debounceDelay as options.

Usage

example/src/app.jsx

import AttachHandler from '../../lib/AttachHandler';

class App extends Component {
    handleMouseMove = () => {
        console.log(`mousemove ${this.iamhere} Hello`);
    };

    iamhere = 'Something is here';

    render = () => {
        return (
            <section
                className="app">
                <AttachHandler
                    target="window"
                    events={{
                        resize: this.handleMouseMove,
                    }}
                    />
            </section>
        );
    }
}

Dependencies

Dev Dependencies

License

MIT