๐โโ๏ธ 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.
Very simple hook for React to have a named boolean in a useState hook.
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
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
.