Socket
Socket
Sign inDemoInstall

@biggerpixel/use-on-click-outside

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @biggerpixel/use-on-click-outside

Custom React Hook used to detect clicks outside of a specified element.


Version published
Weekly downloads
9
increased by80%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

use-on-click-outside

Usage


npm i @biggerpixel/use-on-click-outside
import React, { useRef } from 'react';
import useBoolState from '@biggerpixel/use-bool-state';
import useOnClickOutside from '@biggerpixel/use-on-click-outside';

const Component = () => {
  const elementWrapper = useRef<HTMLDivElement>(null);
  const [isOpen, toggleIsOpen] = useBoolState(false);

  useOnClickOutside(elementWrapper, toggleIsOpen);

  return (
    isOpen && (
      <div ref={elementWrapper}>
        <h2>Content!</h2>
        <p>(Click outside to close)</p>
      </div>
    )
  );
};

export default Component;

FAQs

Last updated on 11 Oct 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc