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

1.0.3 • Public • Published

react-use-toggle

Basically, what this hook does is that, it takes a parameter with value true or false and toggles that value to opposite. It's useful when we want to take some action into it's opposite action, for example: show and hide modal, show more/show less text, open/close side menu.

Usage

npm i @reactdev/react-use-toggle
import useToggle from "@reactdev/react-use-toggle";
function App() {
  // Call the hook which returns, current value and the toggler function

  const [isTextChanged, setIsTextChanged] = useToggle();

  return (
    <button onClick={setIsTextChanged}>
      {isTextChanged ? "Toggled" : "Click to Toggle"}
    </button>
  );
}

Readme

Keywords

Package Sidebar

Install

npm i @reactdev/react-use-toggle

Weekly Downloads

0

Version

1.0.3

License

ISC

Unpacked Size

14.8 kB

Total Files

8

Last publish

Collaborators

  • sonal_sithara