useToggle
A custom React hook to toggle between given values.
Example
Loading...
Install
npx shadcn@latest add https://unlogg.com/r/use-toggle.jsonpnpm dlx shadcn@latest add https://unlogg.com/r/use-toggle.jsonbunx shadcn@latest add https://unlogg.com/r/use-toggle.jsonNotes
-
Allows toggling between any set of values, not just
trueandfalse. You can provide an array of values to toggle between. -
Default to toggling between
falseandtrueif no options are provided. -
The
togglefunction can optionally accept a value to set directly, bypassing the toggle logic.
API Reference
Parameters
| Prop | Type | Default |
|---|---|---|
options? | readonly T[] | [false, true] |
Returns
| Prop | Type | Default |
|---|---|---|
toggle? | (value?: React.SetStateAction<T>) => void | - |
value? | T | - |