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

react-use-clickout

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-use-clickout

custom react hook to handle an event on click ouside of a component

  • 0.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

icon

react-use-clickout

Build Status Coverage Status

It's a custom hook that handles an event after clicking out of the component

Get started

Alright, let's go. First you should install the library

Installing

Using yarn

yarn add react-use-clickout

Or npm

npm i react-use-clickout

Prefer to install it derectly on your project, not globally

Using

import React from 'react';
import useClickout from 'react-use-clickout';


function App() {
  const [
    ref, // it's to be assigned to the component reference
    bindHandler // it's a function to bind a callback handler
  ] = useClickout();
  
  /**
   * The function passed as a callback will be called 
   * if clicked out of the referenced component 
   */
  bindHandler(() => {
    console.log('clickout');
  });

  return (
    <div>
      <p ref={ref}>
        Referenced component 
      </p>
      <div>
        It's out of the referenced component
      </div>
    </div>
  );
}

export default App;

Changing Events is possible. You can pass an array with the events to be listened. The default are mousedown and touchstart.

const [ref, bindClickout] = useClickout(['click']);

Although the name of this library is clickout, it isn't only about click event.

Pre requisites

It has the react@^16.8.0 and react-dom@^16.8.0 as peer-dependencies

Contributing

Keywords

FAQs

Package last updated on 03 Dec 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