JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 313579
  • Score
    100M100P100Q170937F
  • License MIT

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

Package Exports

  • react-event-listener

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-event-listener) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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 from 'react';
import EventListener from 'react-event-listener';

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

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

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

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

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

License

MIT