Skip to content
This repository was archived by the owner on Mar 11, 2023. It is now read-only.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🙋‍♂️ Made by @koenbrouwer.

⚠️ This hook is now part of my collection of hooks called react-grapple. Feel free to open an issue or a pull request in that repo on GitHub! The current repository is still usable, but no longer maintained. If you want to use an up to date and supported version of the useToggle-hook, use react-grapple instead.


react-usetoggle

Very simple hook for React to have a named boolean in a useState hook.

Quick Start

This is a Node.js package available through the npm registry. Installation into your project is done with the npm install command:

To install:

npm install --save @koenbrouwer/react-usetoggle

Usage:

const [state, toggleState] = useToggle(); // defaults to false

You can also give it another default initial state:

const [state, toggleState] = useToggle(true); // defaults to true

If you don't give it a default value, it will default to false, or the boolean you feed it. And thentoggleState() will toggle the value from true to false, or false to true.

License

MIT

About

React hook that toggles a boolean based on the useState hook.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages