useSwitch

Provides the behavior and accessibility implementation for a switch component. A switch is similar to a checkbox, but represents on/off values as opposed to selection.

note

React Native has a Native Switch component. You may only need this hook If you're building a custom Switch.

Install#

yarn add @react-native-aria/switch

Import#

import { useSwitch } from '@react-native-aria/switch'

API#

useSwitch(
props: AriaSwitchProps,
state: ToggleState,
ref: RefObject<HTMLInputElement>
): SwitchAria

AriaSwitchProps#

ToggleState#

ref#

  • Ref of input element or Pressable/Touchable

SwitchAria#

{
/** Props for the input element. */
inputProps: InputHTMLAttributes<HTMLInputElement> & AccessibilityProps;
}

Usage#

Last updated on by Nishan