Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-outside-click-handler

Package Overview
Dependencies
Maintainers
6
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-outside-click-handler

A React component for dealing with clicks outside its subtree

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
6
Created

What is react-outside-click-handler?

The react-outside-click-handler package is a React component that helps you detect and handle clicks outside of a specified element. This is particularly useful for implementing features like closing dropdowns, modals, or tooltips when a user clicks outside of them.

What are react-outside-click-handler's main functionalities?

Basic Outside Click Handling

This feature allows you to detect clicks outside of a specified element. The `onOutsideClick` prop is used to define the function that will be called when an outside click is detected.

import React from 'react';
import OutsideClickHandler from 'react-outside-click-handler';

function MyComponent() {
  const handleOutsideClick = () => {
    console.log('Clicked outside!');
  };

  return (
    <OutsideClickHandler onOutsideClick={handleOutsideClick}>
      <div>
        Click outside of this div to trigger the handler.
      </div>
    </OutsideClickHandler>
  );
}

export default MyComponent;

Nested Outside Click Handling

This feature demonstrates handling nested outside click events. You can have multiple `OutsideClickHandler` components nested within each other, each with its own `onOutsideClick` handler.

import React from 'react';
import OutsideClickHandler from 'react-outside-click-handler';

function MyComponent() {
  const handleOutsideClick = () => {
    console.log('Clicked outside the outer div!');
  };

  const handleInnerOutsideClick = () => {
    console.log('Clicked outside the inner div!');
  };

  return (
    <OutsideClickHandler onOutsideClick={handleOutsideClick}>
      <div>
        Outer Div
        <OutsideClickHandler onOutsideClick={handleInnerOutsideClick}>
          <div>
            Inner Div
          </div>
        </OutsideClickHandler>
      </div>
    </OutsideClickHandler>
  );
}

export default MyComponent;

Other packages similar to react-outside-click-handler

FAQs

Package last updated on 27 Sep 2019

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