🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

react-event-listener

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-event-listener

A React component that allow to bind events on the global scope

0.2.0
Source
npm
Version published
Weekly downloads
400K
-6.84%
Maintainers
1
Weekly downloads
 
Created
Source

React event listener

A React component for binding events on the global scope.

npm version npm downloads Build Status

Dependencies DevDependencies

Getting Started

npm install react-event-listener

Usage

import React, {Component} from 'react';
import EventListener from 'react-event-listener';

class MyComponent extends Component {
  handleResize = () => {
    console.log('resize');
  };

  handleMouseMove = () => {
    console.log('mousemove');
  };

  render() {
    return (
      <div>
        <EventListener target={window} onResize={this.handleResize} />
        <EventListener target={document} onMouseMove={this.handleMouseMove} capture={true} />
      </div>
    );
  }
}

Note on Performance

You should avoid passing inline functions for listeners, because this creates a new Function instance on every render, defeating EventListener's shouldComponentUpdate, and triggering an update cycle where it removes its old listeners and adds its new listeners (so that it can stay up-to-date with the props you passed in).

Note on Testing

In this issue from React, TestUtils.Simulate. methods won't bubble up to window or document. As a result, you must use document.dispatchEvent or simulate event using native DOM api.

See our test cases for more information.

Contributing

Note: you need to have Flow 0.23.0 or greater to be installed.

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request

Collaborators

License

MIT

Keywords

react

FAQs

Package last updated on 04 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts