You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A higher order React component that attaches an event listener for events that occur outside of the component element.
All DOM events that bubble are supported. By default, only "mousedown" event listener is attached. See supportedEvents parameter of the ReactOutsideEvent function.
/** * @param {ReactClass} Target The component that defines `onOutsideEvent` handler. * @param {String[]} supportedEvents A list of valid DOM event names. Default: ['mousedown']. * @return {ReactClass} */
Usage
Define a component class and wrap it using ReactOutsideEvent. Your class must define onOutsideEvent method that will be invoked when an outside event occurs, e.g.
importReactfrom'react';importReactDOMfrom'react-dom';importReactOutsideEventfrom'react-outside-event';classPlayerextendsReact.Component{onOutsideEvent=(event)=>{// Handle the event.}render(){return<div>Hello, World!</div>;}}exportdefaultReactOutsideEvent(Player,['click']);
You can attach multiple event listeners at once and selectively handle events with a simple conditional logic, e.g.