title: Detect click outside React component
body: <p>I'm looking for a way to detect if a click event happened outside of a component, as described in this <a href="https://css-tricks.com/dangers-stopping-event-propagation/" rel="noreferrer">article</a>. jQuery closest() is used to see if the target from a click event has the dom element as one of its parents. If there is a match the click event belongs to one of the children and is thus not considered to be outside of the component.</p>
  <p>So in my component, I want to attach a click handler to the <code>window</code>. When the handler fires I need to compare the target with the dom children of my component.</p>
  <p>The click event contains properties like &quot;path&quot; which seems to hold the dom path that the event has traveled. I'm not sure what to compare or how to best traverse it, and I'm thinking someone must have already put that in a clever utility function... No?</p>