UI & Dom
useToggle
Hook for switching between two status values
- Import
- import { useToggle } from '@kubed/hooks;'
- Source
- View source code
- Docs
- Edit this page
- npm
- @kubed/hooks
Usage
useToggle Hook for switching between two state values
useBooleanToggle Hook for switching between true and false values
API
The useToggle hook accepts two parameters:
initialValue– initial valueoptions– two options for switching
Hook returns the new value after the switch and the function used to switch.
1function useToggle<T>(2initialValue: T, options: [T, T]3): readonly [T, (value?: React.SetStateAction<T>) => void]
Params
| Parameters | Default Value | Type | Description |
|---|---|---|---|
| initialValue | - | T | initial value |
| generateId | - | [T, T] | Two options for switching |
Result
| Parameters | Default Value | Type | Description |
|---|---|---|---|
| state | - | T | Value after switching |
| toggle | - | React.SetStateAction<T> | Toggle value |