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 value
  • options – two options for switching

Hook returns the new value after the switch and the function used to switch.

1
function useToggle<T>(
2
initialValue: T, options: [T, T]
3
): readonly [T, (value?: React.SetStateAction<T>) => void]

Params

ParametersDefault ValueTypeDescription
initialValue-Tinitial value
generateId-[T, T]Two options for switching

Result

ParametersDefault ValueTypeDescription
state-TValue after switching
toggle-React.SetStateAction<T>Toggle value