A component for observing clicks outside an element
import Outsider from "react-outsider";
export default class extends React.Component {
constructor() {
super();
this.state = { contentShown: false }
}
render() {
return this.state.contentShown ? (
<Outsider
onOutsideClick={
this.setState(({ contentShown }) => ({
contentShown: !contentShown
}))
}
>
Some content
</Outsider>
) : (
<div />
)
}
}
MIT, Michael Chan