useToggle
A custom React hook to toggle between given values.
Example
Loading...
Install
npx shadcn@latest add https://unlogg.com/r/use-toggle.json
pnpm dlx shadcn@latest add https://unlogg.com/r/use-toggle.json
bunx shadcn@latest add https://unlogg.com/r/use-toggle.json
Notes
-
Allows toggling between any set of values, not just
true
andfalse
. You can provide an array of values to toggle between. -
Default to toggling between
false
andtrue
if no options are provided. -
The
toggle
function 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 | - |