Skip to content

Switch

Switch Primitive

Demo


A control enabling the user to switch between a checked and unchecked state.

Installation

Terminal window
npx @react-native-reusables/cli@latest add switch

Usage

import * as React from 'react';
import { View } from 'react-native';
import { Label } from '~/components/ui/label';
import { Switch } from '~/components/ui/switch';
function Example() {
const [checked, setChecked] = React.useState(false);
return (
<>
<View className='flex-1 justify-center items-center p-6 gap-12'>
<View className='flex-row items-center gap-2'>
<Switch checked={checked} onCheckedChange={setChecked} nativeID='airplane-mode' />
<Label
nativeID='airplane-mode'
onPress={() => {
setChecked((prev) => !prev);
}}
>
Airplane Mode
</Label>
</View>
</View>
</>
);
}

Props

Switch

Extends Pressable props

PropTypeNote
checkedboolean
onCheckedChange(checked: boolean) => void
disabledboolean(optional)
onKeyDown(ev: React.KeyboardEvent) => voidWeb Only (optional)