useToggleState

Provides state management for toggle components like checkboxes and switches.

installyarn add react-stately
version3.32.2
usageimport {useToggleState} from 'react-stately'

API#


useToggleState( (props: ToggleStateOptions )): 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.