Skip to content

Instantly share code, notes, and snippets.

@andrei-cacio
Created March 2, 2019 08:37
Show Gist options
  • Save andrei-cacio/0be4f8de139935a05377ebe927b9594a to your computer and use it in GitHub Desktop.
Save andrei-cacio/0be4f8de139935a05377ebe927b9594a to your computer and use it in GitHub Desktop.
ClickOutside structure
import React, { Component } from 'react';
class ClickOutside extends Component {
handleClick = e => {
console.log('clicking everywhere!');
};
componentDidMount() {
document.addEventListener("click", this.handleClick);
}
componentWillUnmount() {
document.removeEventListener("click", this.handleClick);
}
render() {
return this.props.children
}
}
export default ClickOutside;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment