Skip to content

Switch Primitive

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

Installation

Install the component via your command line.

Terminal window
npx expo install @rn-primitives/switch

Usage

import * as React from 'react';
import * as SwitchPrimitive from '@rn-primitives/switch';
export default function SwitchScreen() {
const [checked, setChecked] = React.useState(false);
return (
<SwitchPrimitive.Root checked={checked} onCheckedChange={setChecked}>
<SwitchPrimitive.Thumb />
</SwitchPrimitive.Root>
);
}

Props

Root

Extends Pressable props

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

Thumb

Extends View props

PropTypeNote
asChildboolean(optional)