Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including react-use-disclosure with all npm packages installed. Try it out:

require("react/package.json"); // react is a peer dependency. var reactUseDisclosure = require("react-use-disclosure")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

react-use-disclosure v1.4.0

Simple React custom hook to handle simple open, close, toggle states

useDisclosure

Node CI

useDiclosure is a React custom hook to perform common open/close behavior on modals, tooltips etc.

🔧 Installation

# Using yarn.
yarn add react-use-disclosure

# Using npm.
npm install react-use-disclosure

🔎 Usage

As useDisclosure return an object, you can get the key that you want:

// At the top of your file.
import { useDisclosure } from "react-use-disclosure";

// Then, in your component.
const {
  isOpen: isModalOpen,
  open: openModal,
  close: closeModal
} = useDisclosure();

const { isOpen: isTooltipOpen, toggle: toggleTooltip } = useDiclosure(true);

// For the example, but the default value is false.
const { isOpen, open, close, toggle } = useDisclosure(false);

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free