Switch
A toggle control that switches between on and off states.
For the complete documentation index, see llms.txt. Use this file to discover all available pages.
A controlled toggle. Pair value with onValueChange to manage state from React.
Installation
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
Usage
Basic switch
import { useState } from 'react'; import { Host, Switch } from '@expo/ui'; export default function SwitchExample() { const [enabled, setEnabled] = useState(false); return ( <Host matchContents> <Switch value={enabled} onValueChange={setEnabled} /> </Host> ); }
With label
When label is provided, the switch is rendered alongside its text in a labeled row.
import { useState } from 'react'; import { Host, Switch } from '@expo/ui'; export default function LabeledSwitchExample() { const [notifications, setNotifications] = useState(true); return ( <Host style={{ flex: 1 }}> <Switch label="Enable notifications" value={notifications} onValueChange={setNotifications} /> </Host> ); }
API
import { Switch } from '@expo/ui';
Component
Type: React.Element<SwitchProps>
A toggle control that switches between on and off states.
Props for the Switch component, a toggle control.
booleanWhether the switch is disabled. Disabled switches do not respond to user interaction.
ModifierConfig[]Platform-specific modifier escape hatch. Pass an array of modifier configs
from @expo/ui/swift-ui/modifiers or @expo/ui/jetpack-compose/modifiers.
stringIdentifier used to locate the component in end-to-end tests.