@hulkhooks/use-toggle
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

Introduction

Basically, what this hook does is switch a parameter's true or false value to the inverse. It comes in handy when we wish to change one action into its opposite action, such as when we want to reveal or hide a modal, show more or less text, or open or close a side menu.

Installation

# Npm
npm install @hulkhooks/use-toggle --save
# yarn
yarn add @hulkhooks/use-toggle
# pnpm
pnpm add @hulkhooks/use-toggle

Usage

function UseToggleExample() {
  const [isTextChanged, setIsTextChanged] = useToggle();
  return (
    <>
      {isTextChanged.toString()}
      <button onClick={setIsTextChanged}>
        {isTextChanged ? "Toggled" : "Click to Toggle"}
      </button>
    </>
  );
}

Try It

Edit objective-darkness-jixj5i

Package Sidebar

Install

npm i @hulkhooks/use-toggle

Weekly Downloads

1

Version

1.0.4

License

MIT

Unpacked Size

8.58 kB

Total Files

14

Last publish

Collaborators

  • projectashik