Detect click outside React component

后端 未结 30 1223
日久生厌
日久生厌 2020-11-22 13:54

I\'m looking for a way to detect if a click event happened outside of a component, as described in this article. jQuery closest() is used to see if the target from a click e

30条回答
  •  逝去的感伤
    2020-11-22 14:17

    If you want to use a tiny component (466 Byte gzipped) that already exists for this functionality then you can check out this library react-outclick.

    The good thing about the library is that it also lets you detect clicks outside of a component and inside of another. It also supports detecting other types of events.

提交回复
热议问题