0.1.0 • Published 10 years ago
react-global-event-method v0.1.0
Allows declarative event listeners for global events on react components. Inspired by this comment
Install
npm install --save react-global-event-methodUsage
The arguments are onGlobalEvent(eventName, eventTarget=window, useCapture=false).
Cleanup is done for you, and you may register multiple handlers and multiple events per handler.
import onGlobalEvent from 'react-global-event-method';
class MyComponent extends React.Component {
@onGlobalEvent('click')
handleGlobalClick(event){
this.setState(...);
}
render(){
// ...
}
}NOTE!
If you declare componentDidMount or componentWillUnmount they must be above any @onGlobalEvent listeners.