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

auto-hide-hook

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

auto-hide-hook

Autohide is a hook that close mobile menu dropdown bar when you scroll down or click outside the dropdown bar

  • 1.1.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Auto Hide Hook

npm

Description

This is a React hook that will hide mobile menu dropdown bar if you click, touch or scroll outside of the dropdown menu.

Usage

To use this hook you need to set a useRef to the element you want use as a reference and a setShow function to set the state of the element you want to hide. The hook will return a function that will hide the element when you click, touch or scroll outside of the element.

Install npm or yarn

npm i auto-hide-hook

or

yarn add auto-hide-hook

Import

import useAutoHide from 'auto-hide-hook';

Parameters

useAutoHide(ref, setShow);

Example

import React, { useRef, useState } from 'react';
import useAutoHide from 'auto-hide-hook';

const App = () => {
  const [show, setShow] = useState(false);
  const ref = useRef(null);
  useAutoHide(ref, setShow);

  return (
    <div ref={ref}>
      <div className={show ? 'show' : 'hide'}>Hello World</div>
      <button onClick={() => setShow(!show)}>Toggle</button>
    </div>
  );
};

export default App;

CSS

.hide {
  display: none;
}

.show {
  display: block;
}

License

ISC

Author

Raul Jimenez

Website

RaulWebDev.com

Keywords

FAQs

Package last updated on 17 Apr 2023

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