A Higher Order Component wrapper to provide click outside functionality to the components
- Import
clickOutside
component - Wrap your main component with function the
clickOutside
- Provide an
onClickOutside
callback.
import React from 'react';
/* Any component, which will be set onClickOutside */
import Modal from 'modal/Modal';
import clickOutside from 'react-hoc-outside-click';
class AnyComponent extends Component {
state = {
isOpened: false
}
handleClickOutside() {
this.setState({ isOpened: false });
},
render() {
const wrapClickDiv = clickOutside(Modal);
return (
<wrapClickDiv onClickOutside={this.handleClickOutside}>
Any content
</wrapClickDiv>
)
},
});
export default AnyComponent;
Name | Description | Required |
---|---|---|
onClickOutside | function that is called when a click happened outside of the component | yes |
MIT