Skip to content

MihaChicken/react-attach-handler

 
 

Repository files navigation

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

About

React attach event handlers to targets.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.9%
  • HTML 0.1%