Socket
Socket
Sign inDemoInstall

outside-click-handler

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

outside-click-handler

Outside click handler for React


Version published
Maintainers
1
Created
Source

OutsideClickHandler

Greenkeeper badge npm FlowType compatible

This component is designed to handle all clicks outside, for example, to open and close modal windows.

Features

  • Easy to use
  • Tests covered
  • Flowtype definitions
  • Lightweight (2.8kb gzip)

API

The component accepts two types of props: children and callback function. At componentDidMount() adds the listener, who is waiting for the click event, and componentWillUnmount() is removed.

type Props = {
  children: React.Node,
  onOutsideClick: Function,
};

How to use

class Wrapper extends React.Component {
  onClick = () => this.setState({ isShownHidden: !this.state.isShownHidden });

  render() {
    const { isShownHidden } = this.state;
    return (
      <OutsideClickHandler onOutsideClick={this.onClick}>
        <span>Im your child!</span>
        {isShownHidden && <span>Im your hidden child!</span>}
      </OutsideClickHandler>
    );
  }
}

Performance

If you want to use a component in lists, use conditions or methods to avoid poor performance.

Support

If you have any questions, please email me at botev.st@gmail.com or open the issue.

To use static typing, make sure that you have installed Flow.

Keywords

FAQs

Package last updated on 03 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc