Wraps a react component and listens for clicks outside of the element.
Can be used as a higher-order component or as an ES7 class decorator
npm i react-outside
Parameters
config
objectconfig.events
array
// ES7
import React from 'react';
import clickOutside from 'react-outside';
@clickOutside() // Enhanced component
class MyComponent extends React.Component {
handleClickOutside() {
// Handle the event
}
render() {
<ul className="dropdown-menu">
<li>List items...</li>
</ul>
}
}
export default MyComponent; // Component is exported with `clickOutside` decorator
// ES5
var React = require('react');
var clickOutside = require('react-outside');
class MyComponent extends React.Component {
handleClickOutside() {
// Handle the event
}
render() {
<ul className="dropdown-menu">
<li>List items...</li>
</ul>
}
}
export default clickOutside()(MyComponent); // Enhanced component