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.
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
- 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
License
MIT