useToggleState

Provides state management for toggle components like checkboxes and switches.

installyarn add @react-stately/toggle
version3.2.2
usageimport {useToggleState} from '@react-stately/toggle'

API#


useToggleState( (props: ToggleProps )): ToggleState

Interface#


Properties

NameTypeDescription
isSelectedbooleanWhether the toggle is selected.

Methods

MethodDescription
setSelected( (isSelected: boolean )): voidUpdates selection state.
toggle(): voidToggle the selection state.

Example#


See the docs for useCheckbox in react-aria for an example of useToggleState.