Skip to content

Latest commit

 

History

History
130 lines (113 loc) · 8.57 KB

README.md

File metadata and controls

130 lines (113 loc) · 8.57 KB

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