All Projects β†’ oliviertassinari β†’ React Event Listener

oliviertassinari / React Event Listener

Licence: mit
A React component for binding events on the global scope. πŸ’«

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Event Listener

croatoan
Common Lisp bindings for the ncurses terminal library.
Stars: ✭ 111 (-69.08%)
Mutual labels:  binding
spa-bus
πŸ”₯Tools for multilevel components to pass values in any SPA
Stars: ✭ 15 (-95.82%)
Mutual labels:  event
Ics Py
Pythonic and easy iCalendar library (rfc5545)
Stars: ✭ 322 (-10.31%)
Mutual labels:  event
FABGen
C++ binding generator for CPython 3.x (x>=2), Lua 5.3 and Go
Stars: ✭ 26 (-92.76%)
Mutual labels:  binding
EventHandlerInSingleApplication
A sample project about how to create event subscribe/publish feature in single application in asp.net core
Stars: ✭ 16 (-95.54%)
Mutual labels:  event
Android Viewmodelbinding
A lightweight library aiming to speed up Android app development by leveraging the new Android Data Binding together with the Model-View-ViewModel design pattern.
Stars: ✭ 308 (-14.21%)
Mutual labels:  binding
raylib-nelua
Raylib wrapper to nelua language
Stars: ✭ 27 (-92.48%)
Mutual labels:  binding
Laravel Event Sourcing
The easiest way to get started with event sourcing in Laravel
Stars: ✭ 353 (-1.67%)
Mutual labels:  event
Multiplatform-Bus
Kotlin event-bus compatible with Android & native iOS
Stars: ✭ 43 (-88.02%)
Mutual labels:  event
Event
The Hoa\Event library
Stars: ✭ 319 (-11.14%)
Mutual labels:  event
async-script-loader
Asynchronous script loading for SPAs
Stars: ✭ 15 (-95.82%)
Mutual labels:  event
jsheroes.io
The official JSHeroes website
Stars: ✭ 35 (-90.25%)
Mutual labels:  event
Fritz2
Easily build reactive web-apps in Kotlin based on flows and coroutines.
Stars: ✭ 308 (-14.21%)
Mutual labels:  binding
phper
A library that allows us to write PHP extensions using pure Rust and using safe Rust whenever possible.
Stars: ✭ 24 (-93.31%)
Mutual labels:  binding
Swoole Src
πŸš€ Coroutine-based concurrency library for PHP
Stars: ✭ 17,175 (+4684.12%)
Mutual labels:  event
growth.dev
[EVENT] API & IPA
Stars: ✭ 46 (-87.19%)
Mutual labels:  event
dom-event-simulate
simulate user interaction with DOM events.
Stars: ✭ 23 (-93.59%)
Mutual labels:  event
Corbind
Kotlin Coroutines binding APIs for Android UI widgets from the platform and support libraries
Stars: ✭ 357 (-0.56%)
Mutual labels:  binding
On Finished
Execute a callback when a request closes, finishes, or errors
Stars: ✭ 335 (-6.69%)
Mutual labels:  event
Jni.hpp
A modern, type-safe, header-only, C++14 wrapper for JNI
Stars: ✭ 313 (-12.81%)
Mutual labels:  binding

react-event-listener

A React component for binding events on the global scope.

npm version npm downloads Build Status

Dependencies DevDependencies

Installation

npm install react-event-listener

The problem solved

This module provides a declarative way to bind events to a global EventTarget. It's using the React lifecycle to bind and unbind at the right time.

Usage

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

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

  handleScroll = () => {
    console.log('scroll');
  };

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

  render() {
    return (
      <div>
        <EventListener
          target="window"
          onResize={this.handleResize}
          onScroll={withOptions(this.handleScroll, {passive: true, capture: false})}
        />
        <EventListener target={document} onMouseMoveCapture={this.handleMouseMove} />
      </div>
    );
  }
}

Note on server-side rendering

When doing server side rendering, document and window aren't available. You can use a string as a target, or check that they exist before rendering the component.

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.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].